
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <time.h>

#if XMONOLITICEXECUTABLE == 1
#include "xrn_crypto.h"
#include "xrn_miners.h"
#else
#include <dlfcn.h>
#endif

#include "parser.h"
#include "parser_settings.h"

#include "parser_functions.h"

#if ( XRN_GNU_LINUX == 1 )
#include <dirent.h>
#include <sys/stat.h>
#include <signal.h>
#include <termios.h>
#elif ( XRN_WINDOWS == 1 )
#include <Windows.h>
#include <tchar.h>
#endif

#include "xrn_lib_interposer.h"
#include "xrn_lib_interposer_dll.h"
#include "lexcheck.h"
#include "lexcheck_backend.h"

// uint16_t params;

extern struct termios oldt, newt;

settings_t set;

#if ( XRN_GNU_LINUX == 1 )
struct termios oldt, newt;
char getch( int pos
 )
{
    char ch;

    tcgetattr( STDIN_FILENO, &oldt );
    newt = oldt;
    newt.c_lflag = newt.c_lflag & ( tcflag_t ) ~ ( ICANON | ECHO );
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );
    ch = ( char ) getchar(  );
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
    if ( ch > 31 ) {
        if ( ch < 127 ) {
            putchar( '*' );
        } else {
            if ( pos > 0 ) {
                putchar( 0x08 );
                putchar( ' ' );
                putchar( 0x08 );
            }

            return 0;
        }

    } else {
        if ( ch != '\n' ) {

            printf( "Not supported character, retry\n" );
            return 27;
        }

    }

    return ch;
}

#endif

unsigned int safe_gets( char *str, unsigned int maxsize
 )
{

    int i;

    char c;

    if ( str == NULL ) {
        return 0;
    }

    for ( i = 0; i < maxsize - 1; i++ ) {

        c = getch( i );
        if ( c == 0 ) {
            str[i - 1] = c;
            i -= 2;
            if ( i < -1 ) {
                i = -1;
            }

        } else {

            str[i] = c;

            if ( str[i] == '\n' ) {

                break;
            }

            if ( str[i] == 27 ) {
                return 0;
                break;
            }

        }

    }

    str[i] = 0;
    return ( unsigned int ) i;

}

int safe_free( void *pt, int size
 )
{
    int i;

    //int j;
    srand( ( unsigned ) time( NULL ) );
    for ( i = 0; i < size / 4; i++ ) {

        ( ( uint32_t * ) pt )[i] = ( uint32_t ) rand(  );
    }

    for ( int j = i; j < size; j++ ) {
        ( ( uint8_t * ) pt )[i] = ( uint8_t ) rand(  );
    }

    free( pt );
    return 0;
}

int safe_free8( void *pt, int size
 )
{
    int i;

    //int j;
    srand( ( unsigned ) time( NULL ) );
    for ( i = 0; i < size; i++ ) {
        ( ( uint8_t * ) pt )[i] = ( uint8_t ) rand(  );
    }

    free( pt );
    return 0;
}

int safe_free32( void *pt, int size
 )
{
    int i;

    //int j;
    srand( ( unsigned ) time( NULL ) );
    for ( i = 0; i < size; i++ ) {
        ( ( uint32_t * ) pt )[i] = ( uint32_t ) rand(  );
    }

    free( pt );
    return 0;
}

void close_all_open_files(
 )
{
    if ( set.cert_asym.subj != NULL ) {
        free( set.cert_asym.subj );
    }

    if ( set.cert_sym.subj != NULL ) {
        free( set.cert_sym.subj );
    }

    if ( set.common_settings.fpmatrix != NULL ) {
        fclose( set.common_settings.fpmatrix );
    }

    if ( set.common_settings.fpmatrix_comp != NULL ) {
        fclose( set.common_settings.fpmatrix_comp );
    }

    if ( set.common_settings.fpresponse != NULL ) {
        fclose( set.common_settings.fpresponse );
    }

    if ( set.common_settings.logerr != NULL ) {
        fclose( set.common_settings.logerr );
    }

    if ( set.common_settings.logwar != NULL ) {
        fclose( set.common_settings.logwar );
    }

    if ( set.common_settings.loginfo != NULL ) {
        fclose( set.common_settings.loginfo );
    }

    if ( set.common_settings.logdbg != NULL ) {
        fclose( set.common_settings.logdbg );
    }

    if ( set.arithmetic_settings.fppoint != NULL ) {
        fclose( set.arithmetic_settings.fppoint );
    }

    if ( set.arithmetic_settings.fpbinomial_key != NULL ) {
        fclose( set.arithmetic_settings.fpbinomial_key );
    }

    if ( set.arithmetic_settings.fpmonomial_key != NULL ) {
        fclose( set.arithmetic_settings.fpmonomial_key );
    }

    if ( set.arithmetic_settings.fpstart_point != NULL ) {
        fclose( set.arithmetic_settings.fpstart_point );
    }

    if ( set.arithmetic_settings.fpmonomial_commitment != NULL ) {
        fclose( set.arithmetic_settings.fpmonomial_commitment );
    }

    if ( set.arithmetic_settings.fpbinomial_commitment != NULL ) {
        fclose( set.arithmetic_settings.fpbinomial_commitment );
    }

    if ( set.arithmetic_settings.fpmonomial_response != NULL ) {
        fclose( set.arithmetic_settings.fpmonomial_response );
    }

    if ( set.arithmetic_settings.fpmonomial_proof != NULL ) {
        fclose( set.arithmetic_settings.fpmonomial_proof );
    }

    if ( set.arithmetic_settings.fpmonovalent_key != NULL ) {
        fclose( set.arithmetic_settings.fpmonovalent_key );
    }

    if ( set.arithmetic_settings.fppolyvalent_proof != NULL ) {
        fclose( set.arithmetic_settings.fppolyvalent_proof );
    }

    if ( set.arithmetic_settings.fppolyvalent_key != NULL ) {
        fclose( set.arithmetic_settings.fppolyvalent_key );
    }

    if ( set.arithmetic_settings.fpsym_signature != NULL ) {
        fclose( set.arithmetic_settings.fpsym_signature );
    }

    if ( set.arithmetic_settings.fpasy_signature != NULL ) {
        fclose( set.arithmetic_settings.fpasy_signature );
    }

    if ( set.arithmetic_settings.fpring_signature != NULL ) {
        fclose( set.arithmetic_settings.fpring_signature );
    }

    if ( set.arithmetic_settings.fphash != NULL ) {
        fclose( set.arithmetic_settings.fphash );
    }

    if ( set.arithmetic_settings.fpsym_certificate != NULL ) {
        fclose( set.arithmetic_settings.fpsym_certificate );
    }

    if ( set.arithmetic_settings.fpasy_certificate != NULL ) {
        fclose( set.arithmetic_settings.fpasy_certificate );
    }

    if ( set.miner_rnd_settings.fp != NULL ) {
        fclose( set.miner_rnd_settings.fp );
    }

    if ( set.miner_ot_settings.fp != NULL ) {
        fclose( set.miner_ot_settings.fp );
    }

    if ( set.dumpencodingparameters.fp != NULL ) {
        fclose( set.dumpencodingparameters.fp );
    }

    if ( set.xm_dec.fpw != NULL ) {
        fclose( set.xm_dec.fpw );
    }

    if ( set.xm_prm.fpw != NULL ) {
        fclose( set.xm_prm.fpw );
    }

    if ( set.xm_det_prm.fpw != NULL ) {
        fclose( set.xm_det_prm.fpw );
    }

    if ( set.xkey_settings.mkey != NULL ) {
        fclose( set.xkey_settings.mkey );
    }

    if ( set.xkey_settings.bkey != NULL ) {
        fclose( set.xkey_settings.bkey );
    }

    if ( set.mk_sp.fpgenerator != NULL ) {
        fclose( set.mk_sp.fpgenerator );
    }

    if ( set.print_header.in != NULL ) {
        fclose( set.print_header.in );
    }

    if ( set.strip_header.plaintext != NULL ) {
        fclose( set.strip_header.plaintext );
    }

    if ( set.strip_header.file != NULL ) {
        fclose( set.strip_header.file );
    }

    for ( int i = 0; i < XRN_MAX_MERGE_PARALLELISM; i++ ) {
        if ( set.merge_header.blockfiles[i] != NULL ) {
            fclose( set.merge_header.blockfiles[i] );
        }

    }

    if ( set.merge_header.mergedblockfile != NULL ) {
        fclose( set.merge_header.mergedblockfile );
    }

    if ( set.make_block.plaintext != NULL ) {
        fclose( set.make_block.plaintext );
    }

    if ( set.make_block.blockfile != NULL ) {
        fclose( set.make_block.blockfile );
    }

    if ( set.ess_settings.fpblockin != NULL ) {
        fclose( set.ess_settings.fpblockin );
    }

    if ( set.ess_settings.fpblockout != NULL ) {
        fclose( set.ess_settings.fpblockout );
    }

    if ( set.dss_settings.fpblockin != NULL ) {
        fclose( set.dss_settings.fpblockin );
    }

    if ( set.dss_settings.fpblockout != NULL ) {
        fclose( set.dss_settings.fpblockout );
    }

    if ( set.eas_settings.fpblockin != NULL ) {
        fclose( set.eas_settings.fpblockin );
    }

    if ( set.eas_settings.fpblockout != NULL ) {
        fclose( set.eas_settings.fpblockout );
    }

    if ( set.das_settings.fpblockin != NULL ) {
        fclose( set.das_settings.fpblockin );
    }

    if ( set.das_settings.fpblockout != NULL ) {
        fclose( set.das_settings.fpblockout );
    }

    if ( set.ringsig_perm.fpsigner_bkey != NULL ) {
        fclose( set.ringsig_perm.fpsigner_bkey );
    }

    if ( set.ringsig_perm.fpverifier_bkey != NULL ) {
        fclose( set.ringsig_perm.fpverifier_bkey );
    }

    if ( set.ringsig_perm.fpsigner_rsig != NULL ) {
        fclose( set.ringsig_perm.fpsigner_rsig );
    }

    if ( set.ringsig_perm.fpverifier_rsig != NULL ) {
        fclose( set.ringsig_perm.fpverifier_rsig );
    }

    if ( set.ringsig_perm.fppermuted_rsig != NULL ) {
        fclose( set.ringsig_perm.fppermuted_rsig );
    }

    if ( set.ringsig_gen.fpinput != NULL ) {
        fclose( set.ringsig_gen.fpinput );
    }

    for ( int i = 0; i < XRN_MAX_DECOYS; i++ ) {
        if ( set.ringsig_gen.fpdecoys[i] != NULL ) {
            fclose( set.ringsig_gen.fpdecoys[i] );
        }

    }

    if ( set.ringsig_gen.receiver_mkey != NULL ) {
        fclose( set.ringsig_gen.receiver_mkey );
    }

    if ( set.ringsig_gen.fpsignature != NULL ) {
        fclose( set.ringsig_gen.fpsignature );
    }

    if ( set.ringsig_ver.fpinput != NULL ) {
        fclose( set.ringsig_ver.fpinput );
    }

    for ( int i = 0; i < XRN_MAX_DECOYS; i++ ) {
        if ( set.ringsig_ver.fpdecoys[i] != NULL ) {
            fclose( set.ringsig_ver.fpdecoys[i] );
        }

    }

    if ( set.ringsig_ver.sender_bkey != NULL ) {
        fclose( set.ringsig_ver.sender_bkey );
    }

    if ( set.ver_sig_asym.fpin != NULL ) {
        fclose( set.ver_sig_asym.fpin );
    }

    if ( set.ver_sig_asym.mkey != NULL ) {
        fclose( set.ver_sig_asym.mkey );
    }

    if ( set.ver_sig_asym.fpsig != NULL ) {
        fclose( set.ver_sig_asym.fpsig );
    }

    if ( set.ver_sig_sym.fpin != NULL ) {
        fclose( set.ver_sig_sym.fpin );
    }

    if ( set.ver_sig_sym.mkey != NULL ) {
        fclose( set.ver_sig_sym.mkey );
    }

    if ( set.ver_sig_sym.fpsig != NULL ) {
        fclose( set.ver_sig_sym.fpsig );
    }

    if ( set.check_monomial_proof.fpmonomial_response != NULL ) {
        fclose( set.check_monomial_proof.fpmonomial_response );
    }

    if ( set.check_monomial_proof_sym_sig.fpplain_text != NULL ) {
        fclose( set.check_monomial_proof_sym_sig.fpplain_text );
    }

    if ( set.check_asymmetric_signature.fpplaintext != NULL ) {
        fclose( set.check_asymmetric_signature.fpplaintext );
    }

    if ( set.check_blocks.input != NULL ) {
        fclose( set.check_blocks.input );
    }

    if ( set.make_checksum.plain_text != NULL ) {
        fclose( set.make_checksum.plain_text );
    }

    if ( set.make_checksum.checksum != NULL ) {
        fclose( set.make_checksum.checksum );
    }

    if ( set.split_s.fpinput != NULL ) {
        fclose( set.split_s.fpinput );
    }

    if ( set.split_s.fpoutsolution != NULL ) {
        fclose( set.split_s.fpoutsolution );
    }

    if ( set.split_s.fpoutchallenge != NULL ) {
        fclose( set.split_s.fpoutchallenge );
    }

    if ( set.join_stream.fpoutsolution != NULL ) {
        fclose( set.join_stream.fpoutsolution );
    }

    if ( set.join_stream.fpoutchallenge != NULL ) {
        fclose( set.join_stream.fpoutchallenge );
    }

    if ( set.join_stream.fpout != NULL ) {
        fclose( set.join_stream.fpout );
    }

    if ( set.hash_file.fpin != NULL ) {
        fclose( set.hash_file.fpin );
    }

    if ( set.hash_file.fpout != NULL ) {
        fclose( set.hash_file.fpout );
    }

    if ( set.sig_sym.plain_text != NULL ) {
        fclose( set.sig_sym.plain_text );
    }

    if ( set.sig_sym.signature != NULL ) {
        fclose( set.sig_sym.signature );
    }

    if ( set.sig_asym.fpin != NULL ) {
        fclose( set.sig_asym.fpin );
    }

    if ( set.sig_asym.fpout != NULL ) {
        fclose( set.sig_asym.fpout );
    }

    if ( set.keyxchg.bke != NULL ) {
        fclose( set.keyxchg.bke );
    }

    if ( set.keyxchg.outmks != NULL ) {
        fclose( set.keyxchg.outmks );
    }

    if ( set.verify_signature_proof.fpplaintext != NULL ) {
        fclose( set.verify_signature_proof.fpplaintext );
    }

    if ( set.comm_bkey.bkey != NULL ) {
        fclose( set.comm_bkey.bkey );
    }

    if ( set.comm_bkey.bkeycomm != NULL ) {
        fclose( set.comm_bkey.bkeycomm );
    }

    if ( set.comm_bkey.mkeycomm != NULL ) {
        fclose( set.comm_bkey.mkeycomm );
    }

    if ( set.comm_cert.cert != NULL ) {
        fclose( set.comm_cert.cert );
    }

    if ( set.comm_cert.bkeycomm != NULL ) {
        fclose( set.comm_cert.bkeycomm );
    }

    if ( set.comm_cert.mkeycomm != NULL ) {
        fclose( set.comm_cert.mkeycomm );
    }

    if ( set.comm_sig.binomial_commitment != NULL ) {
        fclose( set.comm_sig.binomial_commitment );
    }

    if ( set.comm_sig.monomial_commitment != NULL ) {
        fclose( set.comm_sig.monomial_commitment );
    }

    if ( set.comm_sig.plain_text != NULL ) {
        fclose( set.comm_sig.plain_text );
    }

    if ( set.mk_mresp.mresp != NULL ) {
        fclose( set.mk_mresp.mresp );
    }

    if ( set.hash_cmp.fpin != NULL ) {
        fclose( set.hash_cmp.fpin );
    }

    if ( set.pnrg.sp != NULL ) {
        fclose( set.pnrg.sp );
    }

    if ( set.xrn_point.xp != NULL ) {
        fclose( set.xrn_point.xp );
    }

    if ( set.cert_sym.fpmonovalent_key != NULL ) {
        fclose( set.cert_sym.fpmonovalent_key );
    }

    if ( set.cert_sym.cert != NULL ) {
        fclose( set.cert_sym.cert );
    }

    if ( set.cert_asym.fpbinomial_key != NULL ) {
        fclose( set.cert_asym.fpbinomial_key );
    }

    if ( set.cert_asym.cert != NULL ) {
        fclose( set.cert_asym.cert );
    }

    if ( set.conv_type.in != NULL ) {
        // does not need a free since it has been assigned to another fp
        // fclose( set.conv_type.in ); 
    }

    if ( set.conv_type.out != NULL ) {
        fclose( set.conv_type.out );
    }

    if ( set.xrn_make_monovalent_key.polyvalent_key_fpw != NULL ) {
        fclose( set.xrn_make_monovalent_key.polyvalent_key_fpw );
    }

    if ( set.xrn_make_monovalent_key.polyvalent_proof_fpw != NULL ) {
        fclose( set.xrn_make_monovalent_key.polyvalent_proof_fpw );
    }

    if ( set.xrn_make_monovalent_key.monovalent_key_fpw != NULL ) {
        fclose( set.xrn_make_monovalent_key.monovalent_key_fpw );
    }

    if ( set.monovalent_key_verification.polyvalent_proof_fpr != NULL ) {
        fclose( set.monovalent_key_verification.polyvalent_proof_fpr );
    }

    if ( set.exchange_polyvalent_key.fpext_monovalent_key != NULL ) {
        fclose( set.exchange_polyvalent_key.fpext_monovalent_key );
    }

    if ( set.exchange_polyvalent_key.fppolyvalent_key != NULL ) {
        fclose( set.exchange_polyvalent_key.fppolyvalent_key );
    }

    if ( set.enc_settings.in != NULL ) {
        fclose( set.enc_settings.in );
    }

    if ( set.enc_settings.out != NULL ) {
        fclose( set.enc_settings.out );
    }

    if ( set.crc_settings.filein != NULL ) {
        fclose( set.crc_settings.filein );
    }

    if ( set.extract_steganography_block.fileembedded != NULL ) {
        fclose( set.extract_steganography_block.fileembedded );
    }

    if ( set.extract_steganography_block.fileblock != NULL ) {
        fclose( set.extract_steganography_block.fileblock );
    }

    if ( set.make_steganography_block.filesource != NULL ) {
        fclose( set.make_steganography_block.filesource );
    }

    if ( set.make_steganography_block.fileenvelop != NULL ) {
        fclose( set.make_steganography_block.fileenvelop );
    }

    if ( set.make_steganography_block.fileembedded != NULL ) {
        fclose( set.make_steganography_block.fileembedded );
    }

    if ( set.extract_steganography_raw.fileembedded != NULL ) {
        fclose( set.extract_steganography_raw.fileembedded );
    }

    if ( set.extract_steganography_raw.fileraw != NULL ) {
        fclose( set.extract_steganography_raw.fileraw );
    }

    if ( set.make_steganography_raw.filesource != NULL ) {
        fclose( set.make_steganography_raw.filesource );
    }

    if ( set.make_steganography_raw.fileenvelop != NULL ) {
        fclose( set.make_steganography_raw.fileenvelop );
    }

    if ( set.make_steganography_raw.fileembedded != NULL ) {
        fclose( set.make_steganography_raw.fileembedded );
    }

    if ( set.get_capacity.fileenvelop != NULL ) {
        fclose( set.get_capacity.fileenvelop );
    }

}

void set_all_files_to_NULL(
 )
{
    set.common_settings.fpmatrix = NULL;
    set.common_settings.fpmatrix_comp = NULL;
    set.common_settings.fpresponse = NULL;
    set.common_settings.logerr = NULL;
    set.common_settings.logwar = NULL;
    set.common_settings.loginfo = NULL;
    set.common_settings.logdbg = NULL;
    set.arithmetic_settings.fppoint = NULL;
    set.arithmetic_settings.fpbinomial_key = NULL;
    set.arithmetic_settings.fpmonomial_key = NULL;
    set.arithmetic_settings.fpstart_point = NULL;
    set.arithmetic_settings.fpmonomial_commitment = NULL;
    set.arithmetic_settings.fpbinomial_commitment = NULL;
    set.arithmetic_settings.fpmonomial_response = NULL;
    set.arithmetic_settings.fpmonomial_proof = NULL;
    set.arithmetic_settings.fpmonovalent_key = NULL;
    set.arithmetic_settings.fppolyvalent_proof = NULL;
    set.arithmetic_settings.fppolyvalent_key = NULL;
    set.arithmetic_settings.fpsym_signature = NULL;
    set.arithmetic_settings.fpasy_signature = NULL;
    set.arithmetic_settings.fpring_signature = NULL;
    set.arithmetic_settings.fphash = NULL;
    set.arithmetic_settings.fpsym_certificate = NULL;
    set.arithmetic_settings.fpasy_certificate = NULL;
    set.miner_rnd_settings.fp = NULL;
    set.miner_ot_settings.fp = NULL;
    set.dumpencodingparameters.fp = NULL;
    set.xm_dec.fpw = NULL;
    set.xm_prm.fpw = NULL;
    set.xm_det_prm.fpw = NULL;
    set.xkey_settings.mkey = NULL;
    set.xkey_settings.bkey = NULL;
    set.mk_sp.fpgenerator = NULL;
    set.print_header.in = NULL;
    set.strip_header.plaintext = NULL;
    set.strip_header.file = NULL;
    for ( int i = 0; i < XRN_MAX_MERGE_PARALLELISM; i++ )
        set.merge_header.blockfiles[i] = NULL;
    set.merge_header.mergedblockfile = NULL;
    set.make_block.plaintext = NULL;
    set.make_block.blockfile = NULL;
    set.ess_settings.fpblockin = NULL;
    set.ess_settings.fpblockout = NULL;
    set.dss_settings.fpblockin = NULL;
    set.dss_settings.fpblockout = NULL;
    set.eas_settings.fpblockin = NULL;
    set.eas_settings.fpblockout = NULL;
    set.das_settings.fpblockin = NULL;
    set.das_settings.fpblockout = NULL;
    set.ringsig_perm.fpsigner_bkey = NULL;
    set.ringsig_perm.fpverifier_bkey = NULL;
    set.ringsig_perm.fpsigner_rsig = NULL;
    set.ringsig_perm.fpverifier_rsig = NULL;
    set.ringsig_perm.fppermuted_rsig = NULL;
    set.ringsig_gen.fpinput = NULL;
    for ( int i = 0; i < XRN_MAX_DECOYS; i++ )
        set.ringsig_gen.fpdecoys[i] = NULL;

    set.ringsig_gen.receiver_mkey = NULL;
    set.ringsig_gen.fpsignature = NULL;
    set.ringsig_ver.fpinput = NULL;
    for ( int i = 0; i < XRN_MAX_DECOYS; i++ )
        set.ringsig_ver.fpdecoys[i] = NULL;
    set.ringsig_ver.sender_bkey = NULL;
    set.ver_sig_asym.fpin = NULL;
    set.ver_sig_asym.mkey = NULL;
    set.ver_sig_asym.fpsig = NULL;
    set.ver_sig_sym.fpin = NULL;
    set.ver_sig_sym.mkey = NULL;
    set.ver_sig_sym.fpsig = NULL;
    set.check_monomial_proof.fpmonomial_response = NULL;
    set.check_monomial_proof_sym_sig.fpplain_text = NULL;
    set.check_asymmetric_signature.fpplaintext = NULL;
    set.check_blocks.input = NULL;
    set.make_checksum.plain_text = NULL;
    set.make_checksum.checksum = NULL;
    set.split_s.fpinput = NULL;
    set.split_s.fpoutsolution = NULL;
    set.split_s.fpoutchallenge = NULL;
    set.join_stream.fpoutsolution = NULL;
    set.join_stream.fpoutchallenge = NULL;
    set.join_stream.fpout = NULL;
    set.hash_file.fpin = NULL;
    set.hash_file.fpout = NULL;
    set.sig_sym.plain_text = NULL;
    set.sig_sym.signature = NULL;
    set.sig_asym.fpin = NULL;
    set.sig_asym.fpout = NULL;
    set.keyxchg.bke = NULL;
    set.keyxchg.outmks = NULL;
    set.verify_signature_proof.fpplaintext = NULL;
    set.comm_bkey.bkey = NULL;
    set.comm_bkey.bkeycomm = NULL;
    set.comm_bkey.mkeycomm = NULL;
    set.comm_cert.cert = NULL;
    set.comm_cert.bkeycomm = NULL;
    set.comm_cert.mkeycomm = NULL;
    set.comm_sig.binomial_commitment = NULL;
    set.comm_sig.monomial_commitment = NULL;
    set.comm_sig.plain_text = NULL;
    set.mk_mresp.mresp = NULL;
    set.hash_cmp.fpin = NULL;
    set.pnrg.sp = NULL;
    set.xrn_point.xp = NULL;
    set.cert_sym.fpmonovalent_key = NULL;
    set.cert_sym.cert = NULL;
    set.cert_asym.fpbinomial_key = NULL;
    set.cert_asym.cert = NULL;
    set.conv_type.in = NULL;
    set.conv_type.out = NULL;
    set.xrn_make_monovalent_key.polyvalent_key_fpw = NULL;
    set.xrn_make_monovalent_key.polyvalent_proof_fpw = NULL;
    set.xrn_make_monovalent_key.monovalent_key_fpw = NULL;
    set.monovalent_key_verification.polyvalent_proof_fpr = NULL;
    set.exchange_polyvalent_key.fpext_monovalent_key = NULL;
    set.exchange_polyvalent_key.fppolyvalent_key = NULL;
    set.enc_settings.in = NULL;
    set.enc_settings.out = NULL;
    set.crc_settings.filein = NULL;
    set.extract_steganography_block.fileembedded = NULL;
    set.extract_steganography_block.fileblock = NULL;
    set.make_steganography_block.filesource = NULL;
    set.make_steganography_block.fileenvelop = NULL;
    set.make_steganography_block.fileembedded = NULL;
    set.extract_steganography_raw.fileembedded = NULL;
    set.extract_steganography_raw.fileraw = NULL;
    set.make_steganography_raw.filesource = NULL;
    set.make_steganography_raw.fileenvelop = NULL;
    set.make_steganography_raw.fileembedded = NULL;
    set.get_capacity.fileenvelop = NULL;

}

void intHandler( int dummy
 )
{
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
    exit( 0 );
}

int get_uint( char *args, unsigned int *intpt
 )
{
    if ( sscanf( args, "%u", intpt ) == 1 ) {
        return 0;
    }

    return -1;
}

int get_uint8( char *args, uint8_t * intpt
 )
{
    if ( sscanf( args, "%2hhx", intpt ) == 1 ) {
        return 0;
    }

    return -1;
}

int get_longuint( char *args, long unsigned int *intpt
 )
{
    if ( sscanf( args, "%lu", intpt ) == 1 ) {
        return 0;
    }

    return -1;
}

time_t gettime( char *args
 )
{
    time_t seconds = 0;

    long int minutes;
    long int hours;
    long int days;
    long int years;
    int timeok = 0;

//RAW format
    if ( sscanf( args, "0x%lux", ( long unsigned int * ) &seconds ) == 1 ) {
        printf( "%ld sec \n", seconds );
        return seconds;
    }

    if ( sscanf( args, "%ld", &seconds ) == 1 ) {
        timeok = 1;
    }

    if ( sscanf( args, "%ld:%ld", &minutes, &seconds ) == 2 ) {
        if ( seconds < 60 ) {
            seconds += minutes * 60 + hours * 3600;
            timeok = 1;
        } else {
            timeok = 0;
        }

    }

    if ( sscanf( args, "%ld:%ld:%ld", &hours, &minutes, &seconds ) == 3 ) {
        if ( minutes < 60 && seconds < 60 ) {
            seconds += minutes * 60 + hours * 3600;
            timeok = 1;
        } else {
            timeok = 0;
        }

    }

    if ( sscanf( args, "%ld:%ld:%ld:%ld", &days, &hours, &minutes, &seconds ) == 4 ) {
        if ( minutes < 60 && hours < 60 && seconds < 365 ) {
            seconds += minutes * 60 + hours * 3600 + days * 86400;
            timeok = 1;
        } else {
            timeok = 0;
        }

    }

    if ( sscanf( args, "%ld:%ld:%ld:%ld:%ld", &years, &days, &hours, &minutes, &seconds ) == 5 ) {
        if ( minutes < 60 && hours < 60 && days < 365 && seconds < 60 ) {
            seconds += minutes * 60 + hours * 3600 + days * 86400 + years * 31536000;
            timeok = 1;
        } else {
            timeok = 0;
        }

    }

    if ( timeok == 0 ) {
        printf( "error in time format\n" );
    }

    return seconds;
}

int permutation_get( int argc, char *argv[], char *all_args[]
 )
{

    int i;
    char librarypath[256];

    set.xrnlib_dll = NULL;

    for ( i = 1; i < argc - 2; i++ ) {

        // if permutation config has been specified
        if ( strncmp( argv[i], all_args[XPC_PERMUTATION_CONF], 255 ) == 0 ) {

            // if the architecture flag has been specified
            if ( strncmp( argv[i + 1], all_args[XPC_ARCH], 255 ) == 0 ) {

                if ( strncmp( argv[i + 2], "256", 4 ) == 0 ) {
                    set.xrnlib_dll = dlopen( LIB256, RTLD_NOW | RTLD_GLOBAL );
                    if ( set.xrnlib_dll == NULL ) {
                        return -1;
                    }

                } else if ( strncmp( argv[i + 2], "128", 4 ) == 0 ) {
                    set.xrnlib_dll = dlopen( LIB128, RTLD_NOW | RTLD_GLOBAL );
                    if ( set.xrnlib_dll == NULL ) {
                        return -1;
                    }

                }

                // if the shared library path has been specified
            } else if ( strncmp( argv[i], all_args[XPC_SHARED_LIB], 255 ) == 0 ) {

                strncpy( librarypath, argv[i + 1], 255 );
                set.xrnlib_dll = dlopen( librarypath, RTLD_NOW | RTLD_GLOBAL );

                if ( set.xrnlib_dll == NULL ) {
                    return -1;
                }

            }

        }

    }

    // if the dll has not been opened, try to open the 256 bit version
    if ( set.xrnlib_dll == NULL ) {
        set.xrnlib_dll = dlopen( LIB256, RTLD_NOW | RTLD_GLOBAL );

        // if the dll has not been opened, try to open the 128 bit version
        if ( set.xrnlib_dll == NULL ) {
            set.xrnlib_dll = dlopen( LIB128, RTLD_NOW | RTLD_GLOBAL );

            // if everything has failed return error
            if ( set.xrnlib_dll == NULL ) {

                return -1;

            }

        }

    }

    return 0;

}

void close_everything(
 )
{
    parser_dlclose(  );
    close_all_open_files(  );
}

void parser_dlclose(
 )
{
#if XMONOLITICEXECUTABLE == 0
    if ( set.xrnlib_dll != NULL ) {
        dlclose( set.xrnlib_dll );
    }

#endif
    return;
}

int parser_func( int argc, char *argv[]
 )
{

    int function;
    int argument;
    int ret;
    char *all_args[] = XSTR_ALL_ARGS;

    ret = 0;
    function = 0;

    set_all_files_to_NULL(  );

    tcgetattr( STDIN_FILENO, &oldt );
    signal( SIGINT, intHandler );

#if XMONOLITICEXECUTABLE == 0
    if ( permutation_get( argc, argv, all_args ) < 0 ) {
        printf( "unable to load shared lib " );
        return -1;
    }

#endif

    if ( set_default_initial_settings(  ) != 0 ) {
        close_everything(  );
        return ret;
    }

    for ( argument = 1; argument < argc; argument++ ) {

        // if argv[argument] looks like a command

        if ( is_command( argv[argument] ) == 1 ) {

            if ( argument != 1 ) {

                ret = execute_func( function );
                if ( ret < 0 ) {
                    close_everything(  );
                    return ret;
                }

            }

            // get the function id

            function = command_parser_function( argv[argument], all_args );
            if ( function < 0 ) {

                close_everything(  );
                return -1;

            }

            // if argv[argument] looks like an option

        } else if ( is_option( argv[argument] ) == 1 ) {

            ret = command_parser_option( argv, all_args, function, argc, argument );

            // the command_parser_option returns either a 1 or a 2 if the function returns correctly
            if ( ret == 2 ) {

                argument = argument + 1;

                // the command_parser_option returns a - 1 in case of error
            } else if ( ret != 1 ) {

                close_everything(  );
                return -1;

            }

        }

    }

    ret = execute_func( function );
    if ( ret < 0 ) {
        close_everything(  );
        return ret;
    }

    close_everything(  );
    return 0;

}

int getfile_r( char *args, FILE ** fpout
 )
{

    FILE *fp;

    {
        fp = fopen( args, "r" );
        if ( fp == NULL ) {
            fprintf( set.logfilept, "file %s doesn't exist\n", args );
            return -2;
        };

        *fpout = fp;
    }

    return 0;
}

int getfile_w( char *args, FILE ** fpout
 )
{
    int character_read = 0;
    char c;
    FILE *fp;

    fp = fopen( args, "r" );

    if ( ( fp != NULL ) && ( set.force_write == 0 ) ) {
        fclose( fp );
        printf( "FILE %s already exists, override it? [y/n] : ", args );

        do {
            c = ( char ) getchar(  );
        }

        while ( isspace( c ) );

        if ( c == 'n' ) {
            printf( "abort\n" );
            return -1;
        } else if ( c == 'y' ) {
            printf( "\n" );

        } else {
            printf( "option not recognized \n" );
            return -3;
        }

    }

    fp = fopen( args, "w" );
    if ( fp == NULL ) {
        fprintf( set.logfilept, "unable to open file %s \n", args );
        return -2;
    }

    *fpout = fp;
    return character_read;

}

int getfile_w_append( char *args, FILE ** fpout
 )
{
    int character_read = 0;
    FILE *fp;

    fp = fopen( args, "r" );
    if ( fp != NULL ) {
        fclose( fp );
        fp = fopen( args, "w+" );
    } else {
        fp = fopen( args, "w" );
    }

    if ( fp == NULL ) {
        fprintf( set.logfilept, "unable to open file %s \n", args );
        return -2;
    }

    *fpout = fp;
    return character_read;

    return 0;
}

int get_rndstr( char *args, char *s
 )
{

    int character_read = 0;

    char rnd;
    int rndn;
    FILE *fp;

    fp = fopen( args, "r" );
    if ( fp == NULL ) {
        return -2;
    };
    rndn = 0;
    while ( fscanf( fp, "%c", &rnd ) != EOF && rndn < XRN_BUFF_SIZE ) {
        s[rndn] = rnd;
        rndn++;
    }

    return character_read;
}

int set_default_initial_settings(
 )
{

#if XMONOLITICEXECUTABLE == 0

    xrn_load_default_settings_dll = dlsym( set.xrnlib_dll, "xrn_load_default_settings" );
    if ( xrn_load_default_settings_dll == NULL ) {
        return -1;
    }

    xrn_set_default_log_dll = dlsym( set.xrnlib_dll, "xrn_set_default_log" );
    if ( xrn_set_default_log_dll == NULL ) {
        return -1;
    }

    xrn_check_set_stocastic_settings_dll = dlsym( set.xrnlib_dll, "xrn_check_set_stocastic_settings" );
    if ( xrn_check_set_stocastic_settings_dll == NULL ) {
        return -1;
    }

    xrn_mine_random_settings_dll = dlsym( set.xrnlib_dll, "xrn_mine_random_settings" );
    if ( xrn_mine_random_settings_dll == NULL ) {
        return -1;
    }

#endif

    xrn_set_default_log_dll(  );

    xrn_load_default_settings_dll( &( set.common_settings.xrn_crypto_extra_settings ) );
    xrn_check_set_stocastic_settings_dll( &( set.miner_ot_settings.maxn ), &( set.miner_ot_settings.minn ),
                                          0 );
    xrn_mine_random_settings_dll( &( set.miner_rnd_settings.prob ), 0 );
    set.miner_rnd_settings.max_try = 50000;
    set.miner_ot_settings.max_try = 50000;
    set.conv_type.typein = ( uint32_t ) ( -1 );
    set.conv_type.typeout = ( uint32_t ) ( -1 );
    set.conv_type.in = NULL;
    set.conv_type.out = NULL;

    set.common_settings.enc_password_not_req = 0;
    set.common_settings.enc_password_not_req = 0;

    set.make_steganography_block.folding_en = 1;
    set.get_capacity.folding_en = 1;
    set.cert_asym.subj = NULL;
    set.cert_sym.subj = NULL;

    set.common_settings.xrn_crypto_extra_settings.component_id = PARSER_UNIQUE_ID;
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.check_mode = xrn_manual;
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.check_mode = xrn_manual;
    set.common_settings.enc_no_dis_war = 0;
    set.common_settings.dec_no_dis_war = 0;
    set.common_settings.enc_no_run_war = 0;
    set.common_settings.dec_no_run_war = 0;
    set.logfilept = stdout;

    return 0;

}

int execute_func( int function
 )
{
    int *fn;
    int ret;

    fn = ( int * ) malloc( sizeof( int ) );

    if ( fn != NULL ) {
        *fn = function;
    } else {
        return -1;
    }

    ret = ( command[function].func( ( char * ) fn ) );

    free( fn );

    return ret;

}

char *trim_leading_spaces( char *str
 )
{

    int i, strlength, leading_spaces, char_found;

    strlength = ( int ) strnlen( str, XRNL_MAX_STR_SIZE );

    // remove leading spaces

    leading_spaces = 0;
    char_found = 0;
    for ( i = 0; ( i < XRNL_MAX_STR_SIZE ) && ( i < strlength ) && ( !char_found ); i++ ) {

        if ( ( leading_spaces == i ) && ( isspace( str[i] ) ) ) {
            leading_spaces++;
        } else {
            char_found = 1;
        }

    }

    return &str[leading_spaces];

}

int is_command( char *str
 )
{

    return ( int ) ( strncmp( str, "--", 2 ) == 0 );
}

int is_option( char *str
 )
{

    if ( is_command( str ) ) {
        return 0;
    } else if ( strncmp( str, "-", 1 ) == 0 ) {
        return 1;
    }

    return 0;
}

int command_parser_function( char *str, char *all_args[]
 )
{
    int i;
    size_t lenstr, lenarg, len;
    char *trimmed_str;

    trimmed_str = trim_leading_spaces( str );
    lenstr = strnlen( trimmed_str, XRNL_MAX_STR_SIZE );

    for ( i = 0; i < XLEN_ALL_COMM; i++ ) {

        lenarg = strnlen( all_args[command[i].command], XRNL_MAX_STR_SIZE );

        if ( lenarg > lenstr ) {
            len = lenarg;
        } else {
            len = lenstr;
        }

        if ( strncmp( trimmed_str, all_args[command[i].command], len ) == 0 ) {
            return i;
        }

    }

    return -1;
}

int command_parser_option( char **argv, char *all_args[], int function, int argc, int argindex
 )
{
    int i, j, ret, valid_option, option_index;
    char *str_trimmed;

    parser_callback_option *opt;

    opt = command[function].opt;

    for ( i = argindex; i < argc; i++ ) {

        str_trimmed = trim_leading_spaces( argv[i] );

        // if it is a command return
        if ( is_command( str_trimmed ) ) {
            return 1;
        }

        valid_option = 0;
        option_index = -1;

        for ( j = 0; ( j < command[function].n_opt ) && ( !valid_option ); j++ ) {
            if ( strncmp( str_trimmed, all_args[opt[j].command], XRNL_MAX_STR_SIZE ) == 0 ) {
                valid_option = 1;
                option_index = j;
            }

        }

        // if it is a valid option and it there are other arguments
        if ( ( valid_option == 1 ) && ( i < argc - 1 ) ) {

            i++;

            // see what follows

            str_trimmed = trim_leading_spaces( argv[i] );

            // if what follows is not a command or an option

            if ( ( !is_command( str_trimmed ) ) && ( !is_option( str_trimmed ) ) ) {

                ret = opt[option_index].func( str_trimmed );

                if ( ret == 0 ) {
                    return 2;
                } else {
                    return -1;
                }

                // if what follows is a command 

            } else if ( ( is_option( str_trimmed ) ) || ( is_command( str_trimmed ) ) ) {

                ret = opt[option_index].func( NULL );

                if ( ret == 0 ) {
                    return 1;
                } else {
                    return -1;
                }

            }

            // if it is a valid option and it there are no other arguments
        } else if ( ( valid_option == 1 ) && ( i == argc - 1 ) ) {

            ret = opt[option_index].func( NULL );

            if ( ret == 0 ) {
                return 1;
            } else {
                return -1;
            }

        } else {
            return -1;
        }

    }

    return -1;
}

//GENERAL FUNCTIONS
int file_get( const char *filename, const char *opt, FILE ** fpp
 )
{
    FILE *fp; {
        fp = fopen( filename, opt );
        if ( fp == NULL ) {
            return -2;
        };
        *fpp = fp;
    }

    return 0;
}

/* START*/

//DECONDING CONF

int callback_decoding_conf_opt_compiled_param( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode = std_parameters;
    return 0;
}

int callback_decoding_conf_opt_encoding_param( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode = xrn_parameters;
    return getfile_r( args,
                      &( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
                         encoding_parameters_fp ) );
}

int callback_decoding_conf_opt_init_file( char *args
 )
{
    if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode == xrn_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode =
            xrn_parameters_plus_file;
    }

    else if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode ==
              std_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode =
            std_parameters_plus_file;
    }

    set.common_settings.dec_password_set = 1;
    return getfile_r( args,
                      &( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
                         initialization_file_fp ) );
}

int callback_decoding_conf_opt_no_param( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode = no_encoding;
    set.common_settings.dec_password_set = 1;
    return 0;
}

int callback_decoding_conf_opt_password_str( char *args
 )
{

    unsigned int psw1_l;
    size_t len;

    if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode == std_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode =
            std_parameters_plus_password;
    }

    else if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode ==
              xrn_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode =
            std_parameters_plus_password;
    }

    if ( args != NULL ) {
        sscanf( args, "%256s%n",
                set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.password,
                &psw1_l );
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.password_length =
            ( uint16_t ) psw1_l;
        set.common_settings.dec_password_set = 1;
        len =
            strnlen( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.password,
                     XRN_ENC_PASS_BUFF_SIZE );
        if ( len >= XRN_ENC_PASS_BUFF_SIZE ) {
            printf( "Error: password too large maximum 256 characters\n" );
            return -1;
        }

        else if ( len < ENC_PASS_MIN_SIZE ) {
            printf( "Error: password too short minimum 10 characters\n" );
            return -1;
        }

        return is_valid_password( set.common_settings.xrn_crypto_extra_settings.encoding_settings.
                                  i_settings.password );
    }

    return 0;
}

int callback_decoding_conf_opt_no_password( char *args
 )
{
    set.common_settings.dec_password_set = 1;
    return 0;
}

int callback_decoding_conf_opt_no_running_err( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.check_running_error_en = 0;
    return 0;
}

int callback_decoding_conf_opt_running_err_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
        max_consecutives_01s_threshold_error = in;
    return 0;
}

int callback_decoding_conf_opt_running_war_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
        max_consecutives_01s_threshold_warning = in;
    return 0;
    return 0;
}

int callback_decoding_conf_opt_no_disparity_err( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.check_disparity_error_en = 0;
    return 0;
}

int callback_decoding_conf_opt_disparity_err_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
        max_number_of_01s_threshold_error = in;
    return 0;
}

int callback_decoding_conf_opt_disparity_war_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
        max_number_of_01s_threshold_warning = in;
    return 0;
}

int callback_decoding_conf( char *args
 )
{

    char *psw1, *psw2;
    unsigned int psw1_l, psw2_l;
    int ret = 0;

    if ( set.common_settings.dec_no_run_war == 1 ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
            max_consecutives_01s_threshold_warning =
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
            max_consecutives_01s_threshold_error;
    }

    if ( set.common_settings.dec_no_dis_war == 1 ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
            max_number_of_01s_threshold_warning =
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.
            max_number_of_01s_threshold_error;
    }

    if ( set.common_settings.dec_password_set == 0 ) {
        if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode ==
             std_parameters ) {
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode =
                std_parameters_plus_password;
        }

        else if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode ==
                  xrn_parameters ) {
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.mode =
                std_parameters_plus_password;
        }

        psw1 = malloc( sizeof( char ) * XRN_ENC_PASS_BUFF_SIZE );
        if ( psw1 == NULL ) {
            return -1;
        }

        psw2 = malloc( sizeof( char ) * XRN_ENC_PASS_BUFF_SIZE );
        if ( psw2 == NULL ) {
            free( psw1 );
            return -1;
        }

        printf( "enter decoding password    : " );
        psw1_l = safe_gets( psw1, XRN_ENC_PASS_BUFF_SIZE );
        printf( "\n" );
        ret = is_valid_password( psw1 );
        if ( ret < 0 ) {
            safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
            safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
            return ret;
        }

        if ( psw1_l < ENC_PASS_MIN_SIZE ) {
            printf( "Error: password too short minimum 10 characters\n" );
            safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
            safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
            return -1;
        }

        printf( "re-enter decoding password : " );
        psw2_l = safe_gets( psw2, XRN_ENC_PASS_BUFF_SIZE );
        printf( "\n" );
        if ( ( psw1_l == psw2_l ) && ( strncmp( psw1, psw2, psw1_l ) == 0 ) ) {
            strncpy( set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.password,
                     psw1, psw1_l );
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.i_settings.password_length =
                ( uint16_t ) psw1_l;
        }

        else {
            printf( "passwords doesn't match \n" );
            safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
            safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
            ret = -1;
        }

        safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
        safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
    }

    return ret;
}

//ENCONDING CONF

int callback_encoding_conf_opt_compiled_param( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode = std_parameters;
    return 0;
}

int callback_encoding_conf_opt_encoding_param( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode = xrn_parameters;
    return getfile_r( args,
                      &( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
                         encoding_parameters_fp ) );
}

int callback_encoding_conf_opt_init_file( char *args
 )
{
    if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode == xrn_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode =
            xrn_parameters_plus_file;
    }

    else if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode ==
              std_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode =
            std_parameters_plus_file;
    }

    set.common_settings.enc_password_not_req = 1;
    return getfile_r( args,
                      &( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
                         initialization_file_fp ) );
}

int callback_encoding_conf_opt_no_param( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode = no_encoding;
    set.common_settings.enc_password_not_req = 1;
    return 0;
}

int callback_encoding_conf_opt_password_str( char *args
 )
{

    unsigned int psw1_l;

    if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode == std_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode =
            std_parameters_plus_password;
    }

    else if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode ==
              xrn_parameters ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode =
            std_parameters_plus_password;
    }

    if ( args != NULL ) {
        sscanf( args, "%s%n",
                set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.password,
                &psw1_l );
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.password_length =
            ( uint16_t ) psw1_l;
        set.common_settings.enc_password_not_req = 1;
        if ( psw1_l >= XRN_ENC_PASS_BUFF_SIZE ) {
            printf( "Error: password too large maximum 256 characters\n" );
            return -1;
        }

        else if ( psw1_l < ENC_PASS_MIN_SIZE ) {
            printf( "Error: password too short minimum 10 characters\n" );
            return -1;
        }

        return is_valid_password( set.common_settings.xrn_crypto_extra_settings.encoding_settings.
                                  o_settings.password );
    }

    return 0;
}

int callback_encoding_conf_opt_no_password( char *args
 )
{
    set.common_settings.enc_password_not_req = 1;
    return 0;
}

int callback_encoding_conf_opt_no_running_err( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.check_running_error_en = 0;
    return 0;
}

int callback_encoding_conf_opt_running_err_th( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.check_running_error_en = 1;
    return 0;
}

int callback_encoding_conf_opt_running_war_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
        max_consecutives_01s_threshold_warning = in;
    return 0;
}

int callback_encoding_conf_opt_no_disparity_err( char *args
 )
{
    set.common_settings.enc_no_dis_war = 1;
    return 0;
}

int callback_encoding_conf_opt_disparity_err_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
        max_number_of_01s_threshold_error = in;
    return 0;
}

int callback_encoding_conf_opt_disparity_war_th( char *args
 )
{
    uint32_t in;

    get_uint( args, &in );
    set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
        max_number_of_01s_threshold_warning = in;
    return 0;
}

int callback_encoding_conf( char *args
 )
{
    char *psw1, *psw2;
    unsigned int psw1_l, psw2_l;
    int ret = 0;

    if ( set.common_settings.enc_no_run_war == 1 ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
            max_consecutives_01s_threshold_warning =
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
            max_consecutives_01s_threshold_error;
    }

    if ( set.common_settings.enc_no_dis_war == 1 ) {
        set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
            max_number_of_01s_threshold_warning =
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.
            max_number_of_01s_threshold_error;
    }

    if ( set.common_settings.enc_password_not_req == 0 ) {
        if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode ==
             std_parameters ) {
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode =
                std_parameters_plus_password;
        }

        else if ( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode ==
                  xrn_parameters ) {
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.mode =
                std_parameters_plus_password;
        }

        psw1 = malloc( sizeof( char ) * XRN_ENC_PASS_BUFF_SIZE );
        if ( psw1 == NULL ) {
            return -1;
        }

        psw2 = malloc( sizeof( char ) * XRN_ENC_PASS_BUFF_SIZE );
        if ( psw2 == NULL ) {
            free( psw1 );
            return -1;
        }

        printf( "enter encoding password    : " );
        psw1_l = safe_gets( psw1, XRN_ENC_PASS_BUFF_SIZE );
        printf( "\n" );
        ret = is_valid_password( psw1 );
        if ( ret < 0 ) {
            safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
            safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
            return ret;
        }

        if ( psw1_l < ENC_PASS_MIN_SIZE ) {
            printf( "Error: password too short minimum 10 characters\n" );
            safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
            safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
            return -1;
        }

        printf( "re-enter encoding password : " );
        psw2_l = safe_gets( psw2, XRN_ENC_PASS_BUFF_SIZE );
        printf( "\n" );
        if ( ( psw1_l == psw2_l ) && ( strncmp( psw1, psw2, psw1_l ) == 0 ) ) {

            strncpy( set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.password,
                     psw1, psw1_l );
            set.common_settings.xrn_crypto_extra_settings.encoding_settings.o_settings.password_length =
                ( uint16_t ) psw1_l;
        }

        else {
            printf( "passwords doesn't match \n" );
            ret = -1;
        }

        safe_free( psw1, XRN_ENC_PASS_BUFF_SIZE );
        safe_free( psw2, XRN_ENC_PASS_BUFF_SIZE );
    }

    return ret;
}

int callback_sequence_conf_opt_xmatrix( char *args
 )
{

    return getfile_r( args, &( set.common_settings.fpmatrix ) );
}

int callback_sequence_conf_opt_xmatrix_comp( char *args
 )
{

    return getfile_r( args, &( set.common_settings.fpmatrix_comp ) );
}

int callback_sequence_conf( char *args
 )
{
    return 0;
}

int callback_logging_conf_opt_lib_error_log( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_change_error_log_dll = dlsym( set.xrnlib_dll, "xrn_change_error_log" );
    if ( xrn_change_error_log_dll == NULL ) {
        return -1;
    }

#endif
    if ( set.force_append == 1 ) {
        if ( getfile_w_append( args, &( set.common_settings.logerr ) ) < 0 ) {
            return -1;
        }

    }

    else {
        if ( getfile_w( args, &( set.common_settings.logerr ) ) < 0 ) {
            return -1;
        }

    }

    xrn_change_error_log_dll( set.common_settings.logerr, 1 );
    return 0;
}

int callback_logging_conf_opt_lib_warning_log( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_change_warning_log_dll = dlsym( set.xrnlib_dll, "xrn_change_warning_log" );
    if ( xrn_change_warning_log_dll == NULL ) {
        return -1;
    }

#endif

    if ( set.force_append == 1 ) {
        if ( getfile_w_append( args, &( set.common_settings.logwar ) ) < 0 ) {
            return -1;
        }

    }

    else {
        if ( getfile_w( args, &( set.common_settings.logwar ) ) < 0 ) {
            return -1;
        }

    }

    xrn_change_warning_log_dll( set.common_settings.logwar, 1 );
    return 0;
}

int callback_logging_conf_opt_no_lib_warning_log( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_change_warning_log_dll = dlsym( set.xrnlib_dll, "xrn_change_warning_log" );
    if ( xrn_change_warning_log_dll == NULL ) {
        return -1;
    }

#endif
    xrn_change_warning_log_dll( NULL, 0 );
    return 0;
}

int callback_logging_conf_opt_no_lib_error_log( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_change_error_log_dll = dlsym( set.xrnlib_dll, "xrn_change_error_log" );
    if ( xrn_change_error_log_dll == NULL ) {
        return -1;
    }

#endif

    xrn_change_error_log_dll( NULL, 0 );
    return 0;
}

int callback_logging_conf_opt_lib_info_log( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_change_notification_log_dll = dlsym( set.xrnlib_dll, "xrn_change_notification_log" );
    if ( xrn_change_notification_log_dll == NULL ) {
        return -1;
    }

#endif

    if ( set.force_append == 1 ) {
        if ( getfile_w_append( args, &( set.common_settings.loginfo ) ) < 0 ) {
            return -1;
        }

    }

    else {
        if ( getfile_w( args, &( set.common_settings.loginfo ) ) < 0 ) {
            return -1;
        }

    }

    xrn_change_notification_log_dll( set.common_settings.loginfo, 1 );
    return 0;
}

int callback_logging_conf_opt_lib_debug_log( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_change_debug_log_dll = dlsym( set.xrnlib_dll, "xrn_change_debug_log" );
    if ( xrn_change_debug_log_dll == NULL ) {
        return -1;
    }

#endif

    if ( set.force_append == 1 ) {
        if ( getfile_w_append( args, &( set.common_settings.logdbg ) ) < 0 ) {
            return -1;
        }

    }

    else {
        if ( getfile_w( args, &( set.common_settings.logdbg ) ) < 0 ) {
            return -1;
        }

    }

    xrn_change_debug_log_dll( set.common_settings.logdbg, 1, set.common_settings.debug_seed );
    return 0;
}

int callback_logging_conf_opt_debug_seed( char *args
 )
{

    get_uint( args, &set.common_settings.debug_seed );
    return 0;
}

int callback_logging_conf( char *args
 )
{
    return 0;
}

int callback_logging_conf_opt_force_write( char *args
 )
{
    set.force_write = 1;
    return 0;
}

int callback_logging_conf_opt_force_append( char *args
 )
{
    set.force_append = 1;
    return 0;
}

int callback_permutation_conf_opt_arch( char *args
 )
{
    return 0;
}

int callback_permutation_conf_opt_shared_lib( char *args
 )
{
    return 0;
}

int callback_permutation_conf( char *args
 )
{
    return 0;
}

int callback_dump_encoding_param_opt_encoding_param( char *args
 )
{
    return getfile_w( args, &( set.dumpencodingparameters.fp ) );
}

int callback_dump_encoding_param( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_dump_encoder_parameters_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_dump_encoder_parameters_wrapper" );
    if ( xrn_dump_encoder_parameters_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_dump_encoder_parameters_wrapper_dll( set.common_settings.xrn_crypto_extra_settings.
                                                    encoding_settings.o_settings,
                                                    set.dumpencodingparameters.fp );
}

int callback_decode_encode_opt_to_encode( char *args
 )
{
    return getfile_w( args, &( set.enc_settings.out ) );
}

int callback_decode_encode_opt_to_decode( char *args
 )
{
    return getfile_r( args, &( set.enc_settings.in ) );
}

int callback_decode_encode( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_decode_encode_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_decode_encode_wrapper" );
    if ( xrn_decode_encode_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_decode_encode_wrapper_dll( set.enc_settings.in, set.enc_settings.out,
                                          set.common_settings.xrn_crypto_extra_settings );
}

int callback_option_constanttime( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.const_exec_time = 1;
    return 0;
}

int get_state_size( char *args, uint8_t * st_dest
 )
{
    int character_read = 0;
    int st;

    if ( sscanf( args, "%d%n", &st, &character_read ) < 1 ) {
        return -1;
    }

    else {

        if ( st < 19 )
            *st_dest = ( uint8_t ) st;
        return character_read;
    }

    return 0;
}

int callback_option_state_size( char *args
 )
{
    return get_state_size( args, &( set.common_settings.xrn_crypto_extra_settings.state_size ) );
}

int callback_option_thread_enable( char *args
 )
{
    set.common_settings.xrn_crypto_extra_settings.thread_enable = 1;
    return 0;
}

int get_crc( char *args, uint8_t * crcdest
 )
{

    int character_read = 0;
    int crc;

    if ( sscanf( args, "%d%n", &crc, &character_read ) < 1 ) {
        return -1;
    }

    else {

        if ( crc == 8 || crc == 16 || crc == 32 || crc == 64 ) {
            *crcdest = ( uint8_t ) crc;
            return character_read;
        }

        else {
            return -1;
        }

    }

    return 0;
}

//arithmetic_conf

int callback_arithmetic_conf( char *args
 )
{
    return 0;
}

int callback_arithmetic_conf_opt_point( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fppoint ) );
}

int callback_arithmetic_conf_opt_binomial_key( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpbinomial_key ) );
}

int callback_arithmetic_conf_opt_monomial_key( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpmonomial_key ) );
}

int callback_arithmetic_conf_opt_start_point( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpstart_point ) );
}

int callback_arithmetic_conf_opt_monomial_commitment( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpmonomial_commitment ) );
}

int callback_arithmetic_conf_opt_binomial_commitment( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpbinomial_commitment ) );
}

int callback_arithmetic_conf_opt_monomial_response( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpmonomial_response ) );
}

int callback_arithmetic_conf_opt_monomial_proof( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpmonomial_proof ) );
}

int callback_arithmetic_conf_opt_monovalent_key( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpmonovalent_key ) );
}

int callback_arithmetic_conf_opt_polyvalent_proof( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fppolyvalent_proof ) );
}

int callback_arithmetic_conf_opt_polyvalent_key( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fppolyvalent_key ) );
}

int callback_arithmetic_conf_opt_sym_signature( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpsym_signature ) );
}

int callback_arithmetic_conf_opt_asy_signature( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpasy_signature ) );
}

int callback_arithmetic_conf_opt_ring_signature( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpring_signature ) );
}

int callback_arithmetic_conf_opt_hash( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fphash ) );
}

int callback_arithmetic_conf_opt_sym_certificate( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpsym_certificate ) );
}

int callback_arithmetic_conf_opt_asy_certificate( char *args
 )
{
    return getfile_r( args, &( set.arithmetic_settings.fpasy_certificate ) );
}

int callback_arithmetic_conf_opt_state_size( char *args
 )
{
    return get_state_size( args, &( set.common_settings.xrn_crypto_extra_settings.state_size ) );
}

int callback_arithmetic_conf_opt_crc_bits( char *args
 )
{
    return get_crc( args, &( set.common_settings.xrn_crypto_extra_settings.crc_bytes ) );
}

int callback_arithmetic_conf_opt_rnd_str( char *args
 )
{
    return get_rndstr( args, ( set.common_settings.xrn_crypto_extra_settings.rnd_str ) );
}

int callback_arithmetic_conf_opt_no_thread( char *args
 )
{
    return callback_option_thread_enable( args );
}

int callback_arithmetic_conf_opt_no_const_exec_time( char *args
 )
{
    return callback_option_constanttime( args );
}

//MINER RND

int callback_mine_xmatrix_comp_rnd_opt_prob_ones( char *args
 )
{
    int character_read = 0;

    if ( sscanf( args, "%f%n", &( set.miner_rnd_settings.prob ), &character_read ) < 1 ) {
        return -1;
    }

    else {

        return character_read;
    }

}

int callback_mine_xmatrix_comp_rnd_opt_max_tries( char *args
 )
{
    int character_read = 0;

    if ( sscanf( args, "%u%n", &( set.miner_rnd_settings.max_try ), ( int * ) &character_read )
         < 1 ) {
        return -1;
    }

    else {

        return character_read;
    }

}

int callback_mine_xmatrix_comp_rnd_opt_xmatrix_comp( char *args
 )
{
    return getfile_w( args, &( set.miner_rnd_settings.fp ) );
}

int callback_mine_xmatrix_comp_rnd_opt_pseudo_random( char *args
 )
{
    set.miner_rnd_settings.mode = 1;
    return 0;
}

int callback_mine_xmatrix_comp_rnd_opt_random( char *args
 )
{
    set.miner_rnd_settings.mode = 0;
    return 0;
}

int callback_mine_xmatrix_comp_rnd( char *args
 )
{

    int32_t ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_mine_random_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_mine_random_wrapper" );
    if ( xrn_mine_random_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    if ( set.arithmetic_settings.fppoint == NULL ) {
        set.miner_rnd_settings.mode = 0;
    }

    else {
        set.miner_rnd_settings.mode = 1;
    }

    ret = xrn_mine_random_wrapper_dll( set.miner_rnd_settings.fp, set.miner_rnd_settings.prob, set.miner_rnd_settings.max_try, set.miner_rnd_settings.mode, set.arithmetic_settings.fppoint, set.common_settings.xrn_crypto_extra_settings );   // prob 0.1 max_try 50000
    return ret;
}

//MINER OT, One Third
int callback_mine_xmatrix_comp_ot_opt_min_ones_per_row( char *args
 )
{
    int character_read = 0;

    if ( sscanf( args, "%d%n", &( set.miner_ot_settings.minn ), &character_read ) < 1 ) {
        return -1;
    }

    else {

        return character_read;
    }

}

int callback_mine_xmatrix_comp_ot_opt_max_ones_per_row( char *args
 )
{
    int character_read = 0;

    if ( sscanf( args, "%d%n", &( set.miner_ot_settings.maxn ), &character_read ) < 1 ) {
        return -1;
    }

    else {

        return character_read;
    }

}

int callback_mine_xmatrix_comp_ot_opt_max_tries( char *args
 )
{
    int character_read = 0;

    if ( sscanf( args, "%u%n", &( set.miner_ot_settings.max_try ), &character_read )
         < 1 ) {
        return -1;
    }

    else {

        return character_read;
    }

}

int callback_mine_xmatrix_comp_ot_opt_random( char *args
 )
{
    set.miner_ot_settings.mode = 0;
    return 0;
}

int callback_mine_xmatrix_comp_ot_opt_pseudo_random( char *args
 )
{
    set.miner_ot_settings.mode = 1;
    return 0;
}

int callback_mine_xmatrix_comp_ot_opt_xmatrix_comp( char *args
 )
{
    return getfile_w( args, &( set.miner_ot_settings.fp ) );
}

int callback_mine_xmatrix_comp_ot( char *args
 )
{
    if ( set.miner_ot_settings.mode == 0 ) {
        set.miner_ot_settings.mode = 0;
    }

    else {
        set.miner_ot_settings.mode = 1;
    }

#if XMONOLITICEXECUTABLE == 0
    xrn_mine_stocastic_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_mine_stocastic_wrapper" );
    if ( xrn_mine_stocastic_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return
        xrn_mine_stocastic_wrapper_dll( set.miner_ot_settings.fp,
                                        set.miner_ot_settings.maxn,
                                        set.miner_ot_settings.minn,
                                        set.miner_ot_settings.max_try, set.miner_ot_settings.mode,
                                        NULL, set.common_settings.xrn_crypto_extra_settings );
}

//PERMUTE MATRIX COMPRESSED
int callback_permute_xmatrix_comp_random_opt_xmatrix_comp_dst( char *args
 )
{
    return getfile_w( args, &( set.xm_prm.fpw ) );
}

int callback_permute_xmatrix_comp_random( char *args
 )
{
    int ret;

    if ( set.xm_prm.fpw == NULL ) {

        return -1;
    }

    if ( set.xm_prm.fpw == NULL ) {

        return -1;
    }

#if XMONOLITICEXECUTABLE == 0
    xrn_matrix_compressed_permute_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_matrix_compressed_permute_wrapper" );
    if ( xrn_matrix_compressed_permute_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret =
        xrn_matrix_compressed_permute_wrapper_dll( set.common_settings.fpmatrix_comp, set.xm_prm.fpw,
                                                   set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

//PERMUTE DETERMINISTIC MATRIX COMPRESSED
int callback_permute_xmatrix_comp_deterministic_opt_xmatrix_comp_dst( char *args
 )
{
    return getfile_w( args, &( set.xm_det_prm.fpw ) );
}

int callback_permute_xmatrix_comp_deterministic( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_permute_matrix_compressed_deterministically_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_permute_matrix_compressed_deterministically_wrapper" );
    if ( xrn_permute_matrix_compressed_deterministically_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return
        xrn_permute_matrix_compressed_deterministically_wrapper_dll( set.common_settings.fpmatrix_comp,
                                                                     set.common_settings.fpmatrix,
                                                                     set.xm_det_prm.fpw,
                                                                     set.common_settings.
                                                                     xrn_crypto_extra_settings );
}

int callback_permute_xmatrix_comp_confidential_opt_xmatrix_comp_dst( char *args
 )
{
    return getfile_w( args, &( set.xm_det_prm.fpw ) );
}

int callback_permute_xmatrix_comp_confidential( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_permute_matrix_compressed_key_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_permute_matrix_compressed_key_wrapper" );
    if ( xrn_permute_matrix_compressed_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return
        xrn_permute_matrix_compressed_key_wrapper_dll( set.common_settings.fpmatrix_comp,
                                                       set.common_settings.fpmatrix,
                                                       set.arithmetic_settings.fpmonomial_key,
                                                       set.xm_det_prm.fpw,
                                                       set.common_settings.xrn_crypto_extra_settings );
}

//DECOMPRESS MATRIX

int callback_decompress_xmatrix_opt_xmatrix( char *args
 )
{
    return getfile_w( args, &( set.xm_dec.fpw ) );
}

int callback_decompress_xmatrix( char *args
 )
{
    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_matrix_decompress_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_matrix_decompress_wrapper" );
    if ( xrn_matrix_decompress_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret =
        xrn_matrix_decompress_wrapper_dll( set.common_settings.fpmatrix_comp, set.xm_dec.fpw,
                                           set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

int callback_check_xmatrix_comp( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_matrix_compressed_check_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_matrix_compressed_check_wrapper" );
    if ( xrn_matrix_compressed_check_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    if ( xrn_matrix_compressed_check_wrapper_dll
         ( set.common_settings.fpmatrix_comp, set.common_settings.xrn_crypto_extra_settings ) == XSUCCESS ) {
    }

    return 0;
}

int callback_check_xmatrix( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_matrix_check_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_matrix_check_wrapper" );
    if ( xrn_matrix_check_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    if ( xrn_matrix_check_wrapper_dll
         ( set.common_settings.fpmatrix, set.common_settings.xrn_crypto_extra_settings )
         == XSUCCESS ) {
        return 0;
    }

    return 0;
}

//KEYs GENERATION

//MAKE confidential pseudo random

int callback_make_confidential_pseudo_random_number_opt_next_point( char *args
 )
{
    return getfile_w( args, &( set.xm_prm.fpw ) );
}

int callback_make_confidential_pseudo_random_number( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_generate_confidential_pseudo_random_number_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_generate_confidential_pseudo_random_number_wrapper" );
    if ( xrn_generate_confidential_pseudo_random_number_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_generate_confidential_pseudo_random_number_wrapper_dll( set.arithmetic_settings.fppoint,
                                                                       set.arithmetic_settings.fpmonomial_key,
                                                                       set.common_settings.fpmatrix,
                                                                       set.xm_prm.fpw,
                                                                       set.common_settings.
                                                                       xrn_crypto_extra_settings );
}

int callback_xrn_make_start_point_opt_start_point( char *args
 )
{
    return getfile_w( args, &( set.mk_sp.fpgenerator ) );
//return get_rndstr( args, ( set.common_settings.xrn_crypto_extra_settings.rnd_str ) );
}

int callback_make_start_point( char *args
 )
{

    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_make_start_point_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_start_point_wrapper" );
    if ( xrn_make_start_point_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret =
        xrn_make_start_point_wrapper_dll( set.mk_sp.fpgenerator,
                                          set.common_settings.fpmatrix,
                                          set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

//MONOMIAL KEY

int callback_make_monomial_key_opt_monomial_key( char *args
 )
{
    return getfile_w( args, &( set.xkey_settings.mkey ) );
}

int callback_make_monomial_key( char *args
 )
{

    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_make_monomial_key_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_monomial_key_wrapper" );
    if ( xrn_make_monomial_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret =
        xrn_make_monomial_key_wrapper_dll( set.xkey_settings.mkey,
                                           set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

//BINOMIAL KEY

int callback_make_binomial_key_opt_binomial_key( char *args
 )
{
    return getfile_w( args, &( set.xkey_settings.bkey ) );
}

int callback_make_binomial_key( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_binomial_key_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_binomial_key_wrapper" );
    if ( xrn_make_binomial_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_binomial_key_wrapper_dll( set.common_settings.fpmatrix,     // the Xoron matrix file pointer
                                              set.arithmetic_settings.fpstart_point,    // the start point file pointer
                                              set.arithmetic_settings.fpmonomial_key,   // the monomial key file pointer
                                              set.xkey_settings.bkey,   // the binomial key file pointer
                                              set.common_settings.xrn_crypto_extra_settings );
}

int callback_make_commitment_binomial_key_opt_monomial_commitment( char
                                                                   *args
 )
{
    return getfile_w( args, &( set.comm_bkey.mkeycomm ) );
}

int callback_make_commitment_binomial_key_opt_binomial_commitment( char
                                                                   *args
 )
{
    return getfile_w( args, &( set.comm_bkey.bkeycomm ) );
}

int callback_make_commitment_binomial_key( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_commitment_from_binomial_key_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_commitment_from_binomial_key_wrapper" );
    if ( xrn_make_commitment_from_binomial_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_commitment_from_binomial_key_wrapper_dll( set.common_settings.fpmatrix,
                                                              set.arithmetic_settings.fpbinomial_key,
                                                              set.comm_bkey.mkeycomm,
                                                              set.comm_bkey.bkeycomm,
                                                              set.common_settings.xrn_crypto_extra_settings );
}

int callback_make_response_opt_monomial_response( char *args
 )
{
    return getfile_w( args, &( set.mk_mproof_b.mkeyresp ) );
};

int callback_make_response( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_monomial_response_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_monomial_response_wrapper" );
    if ( xrn_make_monomial_response_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_monomial_response_wrapper_dll( set.mk_mproof_b.mkeyresp,
                                                   set.common_settings.xrn_crypto_extra_settings );
}

int callback_make_monomial_proof_opt_monomial_proof( char *args
 )
{
    return getfile_w( args, &( set.mk_mproof_b.mproof ) );
}

int callback_make_monomial_proof( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_monomial_proof_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_monomial_proof_wrapper" );
    if ( xrn_make_monomial_proof_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_monomial_proof_wrapper_dll( set.arithmetic_settings.fpbinomial_key,
                                                set.common_settings.fpmatrix,
                                                set.arithmetic_settings.fpmonomial_key,
                                                set.arithmetic_settings.fpmonomial_commitment,
                                                set.arithmetic_settings.fpmonomial_response,
                                                set.mk_mproof_b.mproof,
                                                set.common_settings.xrn_crypto_extra_settings );
}

int callback_make_monomial_proof_sym_signature_opt_monomial_proof( char
                                                                   *args
 )
{
    return getfile_w( args, &( set.mk_mproof_s.mproof ) );
}

int callback_make_monomial_proof_sym_signature_opt_plain_text( char
                                                               *args
 )
{
    return getfile_r( args, &( set.mk_mproof_s.pt ) );
}

int callback_make_monomial_proof_sym_signature( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_monomial_proof_from_signature_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_monomial_proof_from_signature_wrapper" );
    if ( xrn_make_monomial_proof_from_signature_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_monomial_proof_from_signature_wrapper_dll( set.mk_mproof_s.pt,
                                                               set.common_settings.fpmatrix,
                                                               set.arithmetic_settings.fpsym_signature,
                                                               set.arithmetic_settings.fpmonomial_key,
                                                               set.arithmetic_settings.fpmonomial_commitment,
                                                               set.arithmetic_settings.fpmonomial_response,
                                                               set.mk_mproof_s.mproof,
                                                               set.common_settings.
                                                               xrn_crypto_extra_settings );
}

int callback_make_monomial_proof_sym_certificate_opt_monomial_proof( char *args
 )
{
    return getfile_w( args, &( set.mk_mproof_c.mproof ) );
}

int callback_make_monomial_proof_sym_certificate( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_monomial_proof_from_sym_certificate_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_monomial_proof_from_sym_certificate_wrapper" );
    if ( xrn_make_monomial_proof_from_sym_certificate_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return
        xrn_make_monomial_proof_from_sym_certificate_wrapper_dll( set.common_settings.fpmatrix,
                                                                  set.arithmetic_settings.fpsym_certificate,
                                                                  set.arithmetic_settings.fpmonomial_key,
                                                                  set.
                                                                  arithmetic_settings.fpmonomial_commitment,
                                                                  set.arithmetic_settings.fpmonomial_response,
                                                                  set.mk_mproof_c.mproof,
                                                                  set.
                                                                  common_settings.xrn_crypto_extra_settings );
}

// MAKE MONOVALENT
int callback_make_monovalent_key_opt_monovalent_key( char *args
 )
{
    return getfile_w( args, &( set.xrn_make_monovalent_key.monovalent_key_fpw ) );
}

int callback_make_monovalent_key_opt_polyvalent_key( char *args
 )
{

    return getfile_w( args, &( set.xrn_make_monovalent_key.polyvalent_key_fpw ) );
}

int callback_make_monovalent_key_opt_polyvalent_proof( char *args
 )
{

    return getfile_w( args, &( set.xrn_make_monovalent_key.polyvalent_proof_fpw ) );
}

int callback_make_monovalent_key_opt_start_timestamp( char *args
 )
{

    set.xrn_make_monovalent_key.start_timestamp = gettime( args );
    if ( set.xrn_make_monovalent_key.start_timestamp >= 0 ) {
        return 0;
    }

    else {
        return -1;
    }

}

int callback_make_monovalent_key_opt_end_timestamp( char *args
 )
{

    set.xrn_make_monovalent_key.end_timestamp = gettime( args );
    if ( set.xrn_make_monovalent_key.end_timestamp > 0 ) {
        return 0;
    }

    else {
        return -1;
    }

}

int callback_make_monovalent_key( char *args
 )
{
    int32_t ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_make_monovalent_key_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_monovalent_key_wrapper" );
    if ( xrn_make_monovalent_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret = xrn_make_monovalent_key_wrapper_dll( set.common_settings.fpmatrix, ( uint64_t )
                                               set.xrn_make_monovalent_key.start_timestamp, ( uint64_t )
                                               set.xrn_make_monovalent_key.end_timestamp,
                                               set.xrn_make_monovalent_key.polyvalent_key_fpw,
                                               set.xrn_make_monovalent_key.polyvalent_proof_fpw,
                                               set.xrn_make_monovalent_key.monovalent_key_fpw,
                                               set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

int callback_make_hash_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.hash_file.fpin ) );
}

int callback_make_hash_opt_hash( char *args
 )
{
    return getfile_w( args, &( set.hash_file.fpout ) );
}

int callback_make_hash( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_hash_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_hash_wrapper" );
    if ( xrn_make_hash_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_hash_wrapper_dll( set.hash_file.fpin,
                                      set.common_settings.fpmatrix,
                                      set.hash_file.fpout, set.common_settings.xrn_crypto_extra_settings );
}

//MAKE SYM SIGNATURE
int callback_make_symmetric_signature_opt_symmetric_signature( char
                                                               *args
 )
{
    return getfile_w( args, &( set.sig_sym.signature ) );
}

int callback_make_symmetric_signature_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.sig_sym.plain_text ) );
}

int callback_make_signature_symmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_signature_symmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_signature_symmetric_wrapper" );
    if ( xrn_make_signature_symmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_signature_symmetric_wrapper_dll( set.sig_sym.plain_text,
                                                     set.arithmetic_settings.fpmonomial_key,
                                                     set.common_settings.fpmatrix,
                                                     set.sig_sym.signature,
                                                     set.common_settings.xrn_crypto_extra_settings );
}

//MAKE ASYMMETRIC SIG
int callback_make_asymmetric_signature_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.sig_asym.fpin ) );
}

int callback_make_asymmetric_signature_opt_asymmetric_signature( char
                                                                 *args
 )
{
    return getfile_w( args, &( set.sig_asym.fpout ) );
}

int callback_make_signature_asymmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_signature_asymmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_signature_asymmetric_wrapper" );
    if ( xrn_make_signature_asymmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_signature_asymmetric_wrapper_dll( set.sig_asym.fpin,
                                                      set.arithmetic_settings.fpmonomial_key,
                                                      set.arithmetic_settings.fpbinomial_key,
                                                      set.common_settings.fpmatrix,
                                                      set.sig_asym.fpout,
                                                      set.common_settings.xrn_crypto_extra_settings );
}

//PERMUTE RING SIGNATURE

int callback_permute_ring_signature_opt_verifier_binomial_key( char *args
 )
{
    return getfile_r( args, &( set.ringsig_perm.fpverifier_bkey ) );
}

int callback_permute_ring_signature_opt_signer_binomial_key( char *args
 )
{
    return getfile_r( args, &( set.ringsig_perm.fpsigner_bkey ) );
}

int callback_permute_ring_signature_opt_signer_ring_signature( char *args
 )
{
    return getfile_r( args, &( set.ringsig_perm.fpsigner_rsig ) );
}

int callback_permute_ring_signature_opt_verifier_ring_signature( char *args
 )
{
    return getfile_r( args, &( set.ringsig_perm.fpverifier_rsig ) );
}

int callback_permute_ring_signature_opt_permuted_ring_signature( char *args
 )
{
    return getfile_w( args, &( set.ringsig_perm.fppermuted_rsig ) );
}

int callback_permute_ring_signature( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_permute_ring_signature_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_permute_ring_signature_wrapper" );
    if ( xrn_permute_ring_signature_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_permute_ring_signature_wrapper_dll( set.ringsig_perm.fpsigner_bkey,
                                                   set.ringsig_perm.fpverifier_bkey,
                                                   set.ringsig_perm.fpsigner_rsig,
                                                   set.ringsig_perm.fpverifier_rsig,
                                                   set.ringsig_perm.fppermuted_rsig,
                                                   set.common_settings.xrn_crypto_extra_settings );
}

//MAKE RING SIGNATURE
uint16_t ringsig_decoys_num = 0;
int callback_make_ring_signature_opt_add_decoy_binomial_key( char *args
 )
{

    int character_read = 0;

    FILE *fp; {
        fp = fopen( args, "r" );
        if ( fp == NULL ) {
            return -2;
        };
        if ( ringsig_decoys_num < XRN_MAX_DECOYS ) {
            set.ringsig_gen.fpdecoys[ringsig_decoys_num] = fp;
        }

        ringsig_decoys_num++;
        set.ringsig_gen.ndecoys = ringsig_decoys_num;
        return character_read;
    }

    return 0;
}

int callback_make_ring_signature_opt_verifier_binomial_key( char *args
 )
{
    return getfile_r( args, &( set.ringsig_gen.receiver_mkey ) );
}

int callback_make_ring_signature_opt_ring_signature( char *args
 )
{
    return getfile_w( args, &( set.ringsig_gen.fpsignature ) );
}

int callback_make_ring_signature_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.ringsig_gen.fpinput ) );
}

int callback_make_ring_signature( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_make_ring_signature_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_ring_signature_wrapper" );
    if ( xrn_make_ring_signature_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_ring_signature_wrapper_dll( set.ringsig_gen.fpinput,
                                                set.ringsig_gen.fpdecoys,
                                                set.arithmetic_settings.fpmonomial_key,
                                                set.arithmetic_settings.fpbinomial_key,
                                                set.ringsig_gen.receiver_mkey,
                                                set.common_settings.fpmatrix,
                                                set.ringsig_gen.ndecoys,
                                                set.ringsig_gen.fpsignature,
                                                set.common_settings.xrn_crypto_extra_settings );
}

// MAKE SYM CERT
int callback_make_symmetric_certificate_opt_subject_str( char *args
 )
{
    size_t len;

    len = strnlen( args, XRN_SUBJECT_CERTIFICATE_LENGTH + 2 );
    if ( len >= XRN_SUBJECT_CERTIFICATE_LENGTH ) {
        return -1;
    }

    else {
        set.cert_sym.subj = malloc( sizeof( char ) * ( len + 1 ) );
        if ( set.cert_sym.subj != NULL )
            strncpy( set.cert_sym.subj, args, len );
        else
            return -1;
    }

    return 0;
}

int callback_make_symmetric_certificate_opt_subject_monovalent_key( char *args
 )
{
    return getfile_r( args, &( set.cert_sym.fpmonovalent_key ) );
}

int callback_make_symmetric_certificate_opt_symmetric_certificate( char
                                                                   *args
 )
{
    return getfile_w( args, &( set.cert_sym.cert ) );
}

int callback_make_symmetric_certificate_opt_start_timestamp( char *args
 )
{
    set.cert_sym.start_v = gettime( args );
    if ( set.cert_sym.start_v > 0 ) {
        return 0;
    }

    else {
        return -1;
    }

}

int callback_make_symmetric_certificate_opt_end_timestamp( char *args
 )
{

    set.cert_sym.stop_v = gettime( args );
    if ( set.cert_sym.stop_v > 0 ) {
        return 0;
    }

    else {
        return -1;
    }

}

int callback_make_certificate_symmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_certificate_symmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_certificate_symmetric_wrapper" );
    if ( xrn_make_certificate_symmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_certificate_symmetric_wrapper_dll( set.arithmetic_settings.fpmonomial_key,
                                                       set.cert_sym.fpmonovalent_key,
                                                       set.cert_sym.subj,
                                                       set.common_settings.fpmatrix,
                                                       ( uint64_t ) set.cert_sym.start_v,
                                                       ( uint64_t ) set.cert_sym.stop_v,
                                                       set.cert_sym.cert,
                                                       set.common_settings.xrn_crypto_extra_settings );
}

//MAKE ASYM CERT

int callback_make_asymmetric_certificate_opt_subject_binomial_key( char *args
 )
{
    return getfile_r( args, &( set.cert_asym.fpbinomial_key ) );
}

int callback_make_asymmetric_certificate_opt_subject_str( char *args
 )
{
    size_t len;

    len = strnlen( args, XRN_SUBJECT_CERTIFICATE_LENGTH + 2 );
    if ( len >= XRN_SUBJECT_CERTIFICATE_LENGTH ) {
        return -1;
    }

    else {
        set.cert_asym.subj = malloc( sizeof( char ) * ( len + 1 ) );
        if ( set.cert_asym.subj != NULL )
            strncpy( set.cert_asym.subj, args, len );
        else
            return -1;
    }

    return 0;
}

int callback_make_asymmetric_certificate_opt_asymmetric_certificate( char *args
 )
{
    return getfile_w( args, &( set.cert_asym.cert ) );
}

int callback_make_asymmetric_certificate_opt_start_timestamp( char *args
 )
{
    set.cert_asym.start_v = gettime( args );
    if ( set.cert_asym.start_v > 0 ) {
        return 0;
    }

    else {
        return -1;
    }

}

int callback_make_asymmetric_certificate_opt_end_timestamp( char *args
 )
{

    set.cert_asym.stop_v = gettime( args );
    if ( set.cert_asym.stop_v > 0 ) {
        return 0;
    }

    else {
        return -1;
    }

}

int callback_make_certificate_asymmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_certificate_asymmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_certificate_asymmetric_wrapper" );
    if ( xrn_make_certificate_asymmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_certificate_asymmetric_wrapper_dll( set.arithmetic_settings.fpmonomial_key,
                                                        set.arithmetic_settings.fpbinomial_key,
                                                        set.cert_asym.fpbinomial_key,
                                                        set.cert_asym.subj,
                                                        set.common_settings.fpmatrix, ( uint64_t )
                                                        set.cert_asym.start_v, ( uint64_t )
                                                        set.cert_asym.stop_v,
                                                        set.cert_asym.cert,
                                                        set.common_settings.xrn_crypto_extra_settings );
}

//MAKE SECURE PSEUDO RANDOM
int callback_make_confidential_pseudo_rand_num_next_point( char *args
 )
{
    return getfile_r( args, &( set.keyxchg.bke ) );
}

//EXCHANGE MONOMIAL
int callback_exchange_monomial_key_opt_external_binomial_key( char *args
 )
{
    return getfile_r( args, &( set.keyxchg.bke ) );
}

int callback_exchange_monomial_key_opt_shared_monomial_key( char *args
 )
{
    return getfile_w( args, &( set.keyxchg.outmks ) );
}

int callback_exchange_monomial_key( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_exchange_monomial_key_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_exchange_monomial_key_wrapper" );
    if ( xrn_exchange_monomial_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_exchange_monomial_key_wrapper_dll( set.common_settings.fpmatrix,
                                                  set.arithmetic_settings.fpbinomial_key,
                                                  set.keyxchg.bke,
                                                  set.arithmetic_settings.fpmonomial_key,
                                                  set.keyxchg.outmks,
                                                  set.common_settings.xrn_crypto_extra_settings );
}

int callback_check_hash_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.hash_cmp.fpin ) );
}

int callback_check_hash( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_hash_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_check_hash_wrapper" );
    if ( xrn_check_hash_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    int ret;

    ret = xrn_check_hash_wrapper_dll( set.hash_cmp.fpin,
                                      set.arithmetic_settings.fphash,
                                      set.common_settings.fpmatrix,
                                      set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

//MONOMIAL PROOF

int callback_check_monomial_proof( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_monomial_proof_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_check_monomial_proof_wrapper" );
    if ( xrn_check_monomial_proof_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_check_monomial_proof_wrapper_dll( set.arithmetic_settings.fpbinomial_key,
                                                 set.common_settings.fpmatrix,
                                                 set.arithmetic_settings.fpbinomial_commitment,
                                                 set.arithmetic_settings.fpmonomial_response,
                                                 set.arithmetic_settings.fpmonomial_proof,
                                                 set.common_settings.xrn_crypto_extra_settings );
}

int callback_check_monomial_proof_sym_signature_opt_plain_text( char
                                                                *args
 )
{
    return getfile_r( args, &( set.check_monomial_proof_sym_sig.fpplain_text ) );
}

int callback_check_monomial_proof_sym_signature( char *args
 )
{
    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_check_monomial_proof_from_signature_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_check_monomial_proof_from_signature_wrapper" );
    if ( xrn_check_monomial_proof_from_signature_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret =
        xrn_check_monomial_proof_from_signature_wrapper_dll( set.check_monomial_proof_sym_sig.fpplain_text,
                                                             set.common_settings.fpmatrix,
                                                             set.arithmetic_settings.fpsym_signature,
                                                             set.arithmetic_settings.fpbinomial_commitment,
                                                             set.arithmetic_settings.fpmonomial_response,
                                                             set.arithmetic_settings.fpmonomial_proof,
                                                             set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

int callback_check_monomial_proof_sym_certificate( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_monomial_proof_from_certificate_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_check_monomial_proof_from_certificate_wrapper" );
    if ( xrn_check_monomial_proof_from_certificate_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_check_monomial_proof_from_certificate_wrapper_dll( set.arithmetic_settings.fpsym_certificate,    // the certificate file pointer
                                                                  set.common_settings.fpmatrix, // the Xoron matrix file pointer
                                                                  set.arithmetic_settings.fpbinomial_commitment,        // the binomial commitment file pointer
                                                                  set.arithmetic_settings.fpmonomial_response,  // the monomial response file pointer
                                                                  set.arithmetic_settings.fpmonomial_proof,     // the monomial proof file pointer
                                                                  set.common_settings.xrn_crypto_extra_settings // the run time settings
         );
}

int callback_check_symmetric_signature_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.verify_signature_proof.fpplaintext ) );
}

int callback_check_signature_symmetric( char *args
 )
{
    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_check_signature_symmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_check_signature_symmetric_wrapper" );
    if ( xrn_check_signature_symmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    ret = xrn_check_signature_symmetric_wrapper_dll( set.verify_signature_proof.fpplaintext,
                                                     set.arithmetic_settings.fpmonomial_key,
                                                     set.common_settings.fpmatrix,
                                                     set.arithmetic_settings.fpsym_signature,
                                                     set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

//RINGSIGNATURE VERIFY

int callback_check_ring_signature_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.ringsig_ver.fpinput ) );
}

int callback_check_ring_signature_opt_signer_binomial_key( char *args
 )
{
    return getfile_w( args, &( set.ringsig_ver.sender_bkey ) );
}

int callback_check_ring_signature( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_ring_signature_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_check_ring_signature_wrapper" );
    if ( xrn_check_ring_signature_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_check_ring_signature_wrapper_dll( set.ringsig_ver.fpinput,
                                                 set.arithmetic_settings.fpring_signature,
                                                 set.arithmetic_settings.fpmonomial_key,
                                                 set.common_settings.fpmatrix,
                                                 set.ringsig_ver.sender_bkey,
                                                 set.common_settings.xrn_crypto_extra_settings );
}

///check monovalent key
int callback_check_monovalent_key_response( char *args
 )
{
    return getfile_w( args, &( set.monovalent_key_verification.polyvalent_proof_fpr ) );
}

int callback_check_monovalent_key( char *args
 )
{
    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_check_monovalent_key_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_check_monovalent_key_wrapper" );
    if ( xrn_check_monovalent_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret = xrn_check_monovalent_key_wrapper_dll( set.common_settings.fpmatrix,
                                                set.arithmetic_settings.fpmonovalent_key,
                                                set.arithmetic_settings.fppolyvalent_proof,
                                                set.common_settings.xrn_crypto_extra_settings );
    return ret;
}

int callback_check_certificate_asymmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_certificate_asymmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_check_certificate_asymmetric_wrapper" );
    if ( xrn_check_certificate_asymmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_check_certificate_asymmetric_wrapper_dll( set.arithmetic_settings.fpbinomial_key,        // issuer binomial key file pointer
                                                         set.common_settings.fpmatrix,  // Xoron matrix key file pointer
                                                         set.arithmetic_settings.fpasy_certificate,     // certificate file pointer
                                                         set.common_settings.xrn_crypto_extra_settings  // run time settings
         );
}

int callback_check_asymmetric_signature_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.check_asymmetric_signature.fpplaintext ) );
}

int callback_check_signature_asymmetric( char *args
 )
{
    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_check_signature_asymmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_check_signature_asymmetric_wrapper" );
    if ( xrn_check_signature_asymmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    ret = xrn_check_signature_asymmetric_wrapper_dll( set.check_asymmetric_signature.fpplaintext, set.arithmetic_settings.fpbinomial_key,       // issuer binomial key file pointer
                                                      set.common_settings.fpmatrix,     // Xoron matrix key file pointer
                                                      set.arithmetic_settings.fpasy_signature,  // certificate file pointer
                                                      set.common_settings.xrn_crypto_extra_settings     // run time settings
         );
    return ret;
}

int callback_make_checksum_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.make_checksum.plain_text ) );
}

int callback_make_checksum_opt_checksum_text( char *args
 )
{
    return getfile_w( args, &( set.make_checksum.checksum ) );
}

int callback_make_checksum( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_checksums_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_checksums_wrapper" );
    if ( xrn_make_checksums_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_checksums_wrapper_dll( set.make_checksum.plain_text,        // input file
                                           set.make_checksum.checksum   // output checksums file pointer
         );
}

int callback_check_complete_blocks_opt_block_file( char *args
 )
{
    return getfile_r( args, &( set.check_blocks.input ) );
}

int callback_check_complete_block( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_complete_blocks_dll = dlsym( set.xrnlib_dll, "xrn_check_complete_blocks" );
    if ( xrn_check_complete_blocks_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_check_complete_blocks_dll( set.check_blocks.input );
}

//check_checksum
int callback_check_checksum_response( char *args
 )
{
    return getfile_r( args, &( set.common_settings.fpresponse ) );
}

int callback_check_checksum_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.make_checksum.plain_text ) );
}

int callback_check_checksum_opt_checksum_text( char *args
 )
{
    return getfile_r( args, &( set.make_checksum.checksum ) );
}

int callback_check_checksum( char *args
 )
{
    int ret;

#if XMONOLITICEXECUTABLE == 0
    xrn_check_checksums_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_check_checksums_wrapper" );
    if ( xrn_check_checksums_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    ret = xrn_check_checksums_wrapper_dll( set.make_checksum.plain_text,        // input file
                                           set.make_checksum.checksum   // output checksums file pointer
         );
    return ret;
}

int callback_make_block_opt_offset( char *args
 )
{
    return get_longuint( args, &( set.make_block.offset ) );
}

int callback_make_block_opt_tag( char *args
 )
{
    return get_uint( args, &( set.make_block.tag ) );
}

int callback_make_block_opt_length( char *args
 )
{
    return get_longuint( args, &( set.make_block.length ) );
}

int callback_make_block_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.make_block.plaintext ) );
}

int callback_make_block_opt_block_file( char *args
 )
{
    return getfile_w( args, &( set.make_block.blockfile ) );
}

int callback_make_block( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_block_dll = dlsym( set.xrnlib_dll, "xrn_make_block" );
    if ( xrn_make_block_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_block_dll( set.make_block.plaintext, set.make_block.blockfile,
                               set.make_block.tag, set.make_block.offset, set.make_block.length );
}

uint8_t merge_block_index = 0;
int callback_combine_block_opt_block_file( char *args
 )
{

    int character_read = 0;

    FILE *fp; {
        fp = fopen( args, "r" );
        if ( fp == NULL ) {
            return -2;
        };
        if ( merge_block_index < XRN_MAX_MERGE_PARALLELISM ) {
            set.merge_header.blockfiles[merge_block_index] = fp;
        }

        merge_block_index++;
        set.merge_header.nblocks = merge_block_index;
        return character_read;
    }

    return 0;
}

int callback_combine_block_opt_combined_block_file( char *args
 )
{
    return getfile_w( args, &( set.merge_header.mergedblockfile ) );
}

int callback_combine_block( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_join_blocks_dll = dlsym( set.xrnlib_dll, "xrn_join_blocks" );
    if ( xrn_join_blocks_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_join_blocks_dll( set.merge_header.blockfiles,
                                set.merge_header.nblocks, set.merge_header.mergedblockfile );
}

int callback_strip_header_from_block_opt_block_file( char *args
 )
{
    return getfile_r( args, &( set.strip_header.file ) );
}

int callback_strip_header_from_block_opt_plain_text( char *args
 )
{
    return getfile_w( args, &( set.strip_header.plaintext ) );
}

int callback_strip_header_from_block( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_strip_header_from_block_dll = dlsym( set.xrnlib_dll, "xrn_strip_header_from_block" );
    if ( xrn_strip_header_from_block_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_strip_header_from_block_dll( set.strip_header.file, set.strip_header.plaintext );
}

int callback_print_header_opt_xrn_file( char *args
 )
{

    return getfile_r( args, &( set.print_header.in ) );
}

int callback_print_header( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_print_metadata_dll = dlsym( set.xrnlib_dll, "xrn_print_metadata" );
    if ( xrn_print_metadata_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_print_metadata_dll( set.print_header.in, set.common_settings.xrn_crypto_extra_settings );
}

int callback_version( char *args
 )
{
    return 0;
};

int callback_print_lib_info( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_dump_library_info_dll = dlsym( set.xrnlib_dll, "xrn_dump_library_info" );
    if ( xrn_dump_library_info_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_dump_library_info_dll( set.common_settings.fpresponse );
}

int callback_convert_hash_to_point_opt_point( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_hash_to_point( char *args
 )
{
    set.conv_type.typein = c_hash;
    set.conv_type.typeout = c_point;
    set.conv_type.in = set.arithmetic_settings.fphash;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_point_to_monomial_key_opt_monomial_key( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_point_to_monomial_key( char *args
 )
{
    set.conv_type.typein = c_point;
    set.conv_type.typeout = c_monomial_key;
    set.conv_type.in = set.arithmetic_settings.fppoint;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_monomial_key_to_point_opt_point( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_binomial_key_to_start_point_opt_start_point( char
                                                                  *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_binomial_key_to_start_point( char *args
 )
{
    set.conv_type.typein = c_binomial_key;
    set.conv_type.typeout = c_start;
    set.conv_type.in = set.arithmetic_settings.fpbinomial_key;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_monomial_key_to_point( char *args
 )
{
    set.conv_type.typein = c_monomial_key;
    set.conv_type.typeout = c_point;
    set.conv_type.in = set.arithmetic_settings.fpmonomial_key;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_start_point_to_point_opt_point( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_start_point_to_point( char *args
 )
{
    set.conv_type.typein = c_start;
    set.conv_type.typeout = c_point;
    set.conv_type.in = set.arithmetic_settings.fpstart_point;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_point_to_start_point_opt_start_point( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_point_to_start_point( char *args
 )
{
    set.conv_type.typein = c_point;
    set.conv_type.typeout = c_start;
    set.conv_type.in = set.arithmetic_settings.fppoint;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_monomial_key_to_monomial_commitment_opt_monomial_commitment( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_monomial_key_to_monomial_commitment( char *args
 )
{
    set.conv_type.typein = c_monomial_key;
    set.conv_type.typeout = c_monomial_commitment;
    set.conv_type.in = set.arithmetic_settings.fpmonomial_key;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_monomial_commitment_to_monomial_key_opt_monomial_key( char
                                                                           *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_monomial_commitment_to_monomial_key( char *args
 )
{
    set.conv_type.typein = c_monomial_commitment;
    set.conv_type.typeout = c_monomial_key;
    set.conv_type.in = set.arithmetic_settings.fpmonomial_commitment;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_asymmetric_certificate_to_binomial_key_opt_binomial_key( char
                                                                              *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_asymmetric_certificate_to_binomial_key( char *args
 )
{
    set.conv_type.typein = c_certificate_asy;
    set.conv_type.typeout = c_binomial_key;
    set.conv_type.in = set.arithmetic_settings.fpasy_certificate;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_hash_to_monomial_key_opt_monomial_key( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_hash_to_monomial_key( char *args
 )
{
    set.conv_type.typein = c_hash;
    set.conv_type.typeout = c_monomial_key;
    set.conv_type.in = set.arithmetic_settings.fphash;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_sym_certificate_to_monovalent_key_opt_monovalent_key( char *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_symmetric_certificate_to_monovalent_key( char
                                                              *args
 )
{
    set.conv_type.typein = c_certificate_sym;
    set.conv_type.typeout = c_monovalent_key;
    set.conv_type.in = set.arithmetic_settings.fpsym_certificate;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

//SPLIT STREAM
int callback_split_symmetric_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.split_s.fpinput ) );
}

int callback_split_symmetric_opt_solution_text( char *args
 )
{
    return getfile_w( args, &( set.split_s.fpoutsolution ) );
}

int callback_split_symmetric_opt_challenge_text( char *args
 )
{
    return getfile_w( args, &( set.split_s.fpoutchallenge ) );
}

int callback_split_symmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_split_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_split_wrapper" );
    if ( xrn_split_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_split_wrapper_dll( set.split_s.fpinput, set.split_s.fpoutchallenge,      //big file challenge
                                  set.split_s.fpoutsolution,    //small file solution
                                  set.common_settings.xrn_crypto_extra_settings );
}

//ASYMMETRIC ENCRYPTION
int callback_encrypt_asymmetric_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.eas_settings.fpblockin ) );
}

int callback_encrypt_asymmetric_opt_cipher_text( char *args
 )
{
    return getfile_w( args, &( set.eas_settings.fpblockout ) );
}

int callback_encrypt_asymmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_encrypt_asymmetric_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_encrypt_asymmetric_wrapper" );
    if ( xrn_encrypt_asymmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return
        xrn_encrypt_asymmetric_wrapper_dll( set.eas_settings.fpblockin,
                                            set.common_settings.fpmatrix,
                                            set.arithmetic_settings.fpbinomial_key,
                                            set.eas_settings.fpblockout,
                                            set.common_settings.xrn_crypto_extra_settings );
}

//SYMMETRIC ENCRIPTION

int callback_encrypt_symmetric_opt_plain_text( char *args
 )
{
    return getfile_r( args, &( set.ess_settings.fpblockin ) );
}

int callback_encrypt_symmetric_opt_cipher_text( char *args
 )
{
    return getfile_w( args, &( set.ess_settings.fpblockout ) );
}

int callback_encrypt_symmetric( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_encrypt_symmetric_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_encrypt_symmetric_wrapper" );
    if ( xrn_encrypt_symmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return
        xrn_encrypt_symmetric_wrapper_dll( set.ess_settings.fpblockin,
                                           set.common_settings.fpmatrix,
                                           set.arithmetic_settings.fpmonomial_key,
                                           set.ess_settings.fpblockout,
                                           set.common_settings.xrn_crypto_extra_settings );
}

//JOIN SYMMETRIC
int callback_join_symmetric_opt_plain_text( char *args
 )
{
    return getfile_w( args, &( set.join_stream.fpout ) );
}

int callback_join_symmetric_opt_solution_text( char *args
 )
{
    return getfile_r( args, &( set.join_stream.fpoutsolution ) );
}

int callback_join_symmetric_opt_challenge_text( char *args
 )
{
    return getfile_r( args, &( set.join_stream.fpoutchallenge ) );
}

int callback_join_symmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_join_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_join_wrapper" );
    if ( xrn_join_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_join_wrapper_dll( set.join_stream.fpoutchallenge,
                                 set.join_stream.fpoutsolution,
                                 set.join_stream.fpout, set.common_settings.xrn_crypto_extra_settings );
}

//DECRYPTION STREAM ASYMMETRIC
int callback_decipher_asymmetric_opt_cipher_text( char *args
 )
{
    return getfile_r( args, &( set.das_settings.fpblockin ) );
}

int callback_decipher_asymmetric_opt_plain_text( char *args
 )
{
    return getfile_w( args, &( set.das_settings.fpblockout ) );
}

int callback_decipher_asymmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_decrypt_asymmetric_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_decrypt_asymmetric_wrapper" );
    if ( xrn_decrypt_asymmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return
        xrn_decrypt_asymmetric_wrapper_dll( set.das_settings.fpblockin,
                                            set.common_settings.fpmatrix,
                                            set.arithmetic_settings.fpmonomial_key,
                                            set.das_settings.fpblockout,
                                            set.common_settings.xrn_crypto_extra_settings );
}

//DECRYPT STREAM SYMMETRIC

int callback_decipher_symmetric_opt_cipher_text( char *args
 )
{
    return getfile_r( args, &( set.dss_settings.fpblockin ) );
}

int callback_decipher_symmetric_opt_plain_text( char *args
 )
{
    return getfile_w( args, &( set.dss_settings.fpblockout ) );
}

int callback_decipher_symmetric( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_decrypt_symmetric_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_decrypt_symmetric_wrapper" );
    if ( xrn_decrypt_symmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_decrypt_symmetric_wrapper_dll( set.dss_settings.fpblockin,
                                              set.common_settings.fpmatrix,
                                              set.arithmetic_settings.fpmonomial_key,
                                              set.dss_settings.fpblockout,
                                              set.common_settings.xrn_crypto_extra_settings );
}

int callback_option_commitment_from_certificate_cert( char *args
 )
{
    return getfile_r( args, &( set.comm_cert.cert ) );
}

int callback_make_commitment_sym_certificates_opt_monomial_commitment( char
                                                                       *args
 )
{
    return getfile_w( args, &( set.comm_cert.mkeycomm ) );
}

int callback_make_commitment_sym_certificates_opt_binomial_commitment( char
                                                                       *args
 )
{
    return getfile_w( args, &( set.comm_cert.bkeycomm ) );
}

int callback_make_commitment_sym_certificate( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_commitment_from_sym_certificate_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_commitment_from_sym_certificate_wrapper" );
    if ( xrn_make_commitment_from_sym_certificate_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_commitment_from_sym_certificate_wrapper_dll( set.arithmetic_settings.fpsym_certificate,
                                                                 set.common_settings.fpmatrix,
                                                                 set.comm_cert.mkeycomm,
                                                                 set.comm_cert.bkeycomm,
                                                                 set.common_settings.
                                                                 xrn_crypto_extra_settings );
}

int callback_make_commitment_sym_signature_opt_monomial_commitment( char
                                                                    *args
 )
{
    return getfile_w( args, &( set.comm_sig.monomial_commitment ) );
}

int callback_make_commitment_sym_signature_opt_binomial_commitment( char
                                                                    *args
 )
{
    return getfile_w( args, &( set.comm_sig.binomial_commitment ) );
}

int callback_make_commitment_sym_signature_opt_plain_text( char
                                                           *args
 )
{
    return getfile_r( args, &( set.comm_sig.plain_text ) );
}

int callback_make_commitment_sym_signature( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_make_commitment_from_sym_signatures_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_make_commitment_from_sym_signatures_wrapper" );
    if ( xrn_make_commitment_from_sym_signatures_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_make_commitment_from_sym_signatures_wrapper_dll( set.comm_sig.plain_text,
                                                                set.common_settings.fpmatrix,
                                                                set.arithmetic_settings.fpsym_signature,
                                                                set.comm_sig.monomial_commitment,
                                                                set.comm_sig.binomial_commitment,
                                                                set.common_settings.
                                                                xrn_crypto_extra_settings );
}

/*2nd step */ int callback_option_xrn_make_monomial_response_mresp( char *args
 )
{
    return getfile_w( args, &( set.mk_mresp.mresp ) );
}

int callback_check_certificate_symmetric( char *args
 )
{
#if XMONOLITICEXECUTABLE == 0
    xrn_check_certificate_symmetric_wrapper_dll =
        dlsym( set.xrnlib_dll, "xrn_check_certificate_symmetric_wrapper" );
    if ( xrn_check_certificate_symmetric_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_check_certificate_symmetric_wrapper_dll( set.arithmetic_settings.fpmonomial_key,
                                                        set.common_settings.fpmatrix,
                                                        set.arithmetic_settings.fpsym_certificate,
                                                        set.common_settings.xrn_crypto_extra_settings );
}

int callback_option_xrn_generate_confidential_pseudo_random_number_sp( char
                                                                       *args
 )
{
    return getfile_r( args, &( set.pnrg.sp ) );
}

//MAKE XPOINT
int callback_make_point_opt_point( char *args
 )
{
    return getfile_w( args, &( set.xrn_point.xp ) );
}

int callback_make_point( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_make_point_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_make_point_wrapper" );
    if ( xrn_make_point_wrapper_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_point_wrapper_dll( set.xrn_point.xp, set.common_settings.xrn_crypto_extra_settings );
}

///xrn_convert_type_wrapper_dll int callback_null( char *args ) { return 1; };
int callback_option_conv_types_fpin( char *args
 )
{
    int ret;

// xrn_lib_xtype_t type;
    ret = getfile_r( args, &( set.conv_type.in ) );
    if ( ret == -2 ) {
        return ret;
    }

    return -1;
}

int callback_exchange_polyvalent_key_opt_external_monovalent_key( char
                                                                  *args
 )
{
    return getfile_r( args, &( set.exchange_polyvalent_key.fpext_monovalent_key ) );
}

int callback_exchange_polyvalent_key_opt_shared_polyvalent_key( char
                                                                *args
 )
{
    return getfile_w( args, &( set.exchange_polyvalent_key.fppolyvalent_key ) );
}

int callback_exchange_polyvalent_key( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_exchange_polyvalent_key_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_exchange_polyvalent_key_wrapper" );
    if ( xrn_exchange_polyvalent_key_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_exchange_polyvalent_key_wrapper_dll( set.common_settings.fpmatrix,       // Xoron matrix file pointer
                                                    set.arithmetic_settings.fpmonovalent_key,   // Xoron internal monovalent key file pointer
                                                    set.exchange_polyvalent_key.fpext_monovalent_key,   // Xoron external monovalent key file pointer
                                                    set.arithmetic_settings.fppolyvalent_key,   // Xoron internal polyvalent key file pointer
                                                    set.arithmetic_settings.fppolyvalent_proof, // Xoron internal polyvalent proof file pointer
                                                    set.exchange_polyvalent_key.fppolyvalent_key,       // output polyvalent key file pointer
                                                    set.common_settings.xrn_crypto_extra_settings       // the run time settings
         );
}

int callback_option_xrn_checksum_dump_fpin( char *args
 )
{
    return getfile_r( args, &( set.crc_settings.filein ) );
}

// extract steganography raw

int callback_extract_steganography_raw_opt_embedded_file( char *args
 )
{
    return getfile_r( args, &( set.extract_steganography_raw.fileembedded ) );
}

int callback_extract_steganography_raw_opt_raw_file( char *args
 )
{
    return getfile_w( args, &( set.extract_steganography_raw.fileraw ) );
}

int callback_extract_steganography_raw( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_extract_steg_raw_dll = dlsym( set.xrnlib_dll, "xrn_extract_steg_raw" );
    if ( xrn_extract_steg_raw_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_extract_steg_raw_dll( set.extract_steganography_raw.fileembedded,
                                     set.extract_steganography_raw.fileraw );
}

// extract steganography block

int callback_extract_steganography_block_opt_embedded_file( char *args
 )
{
    return getfile_r( args, &( set.extract_steganography_block.fileembedded ) );
}

int callback_extract_steganography_block_opt_block_file( char *args
 )
{
    return getfile_w( args, &( set.extract_steganography_block.fileblock ) );
}

int callback_extract_steganography_block( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_extract_steg_block_dll = dlsym( set.xrnlib_dll, "xrn_extract_steg_block" );
    if ( xrn_extract_steg_block_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_extract_steg_block_dll( set.extract_steganography_block.fileembedded,
                                       set.extract_steganography_block.fileblock,
                                       set.common_settings.xrn_crypto_extra_settings );
}

// make steganography raw

int callback_make_steganography_raw_opt_embedded_file( char *args
 )
{
    return getfile_w( args, &( set.make_steganography_raw.fileembedded ) );
}

int callback_make_steganography_raw_opt_envelop_file( char *args
 )
{
    return getfile_r( args, &( set.make_steganography_raw.fileenvelop ) );
}

int callback_make_steganography_raw_opt_source_file( char *args
 )
{
    return getfile_r( args, &( set.make_steganography_raw.filesource ) );
}

int callback_make_steganography_raw( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_make_steg_raw_dll = dlsym( set.xrnlib_dll, "xrn_make_steg_raw" );
    if ( xrn_make_steg_raw_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_steg_raw_dll( set.make_steganography_raw.filesource,
                                  set.make_steganography_raw.fileenvelop,
                                  set.make_steganography_raw.fileembedded );
}

// make steganography block

int callback_make_steganography_block_opt_embedded_file( char *args
 )
{
    return getfile_w( args, &( set.make_steganography_block.fileembedded ) );
}

int callback_make_steganography_block_opt_envelop_file( char *args
 )
{
    return getfile_r( args, &( set.make_steganography_block.fileenvelop ) );
}

int callback_make_steganography_block_opt_source_file( char *args
 )
{
    return getfile_r( args, &( set.make_steganography_block.filesource ) );
}

int callback_make_steganography_block_opt_offset( char *args
 )
{
    return get_longuint( args, &( set.make_steganography_block.offset ) );
}

int callback_make_steganography_block_opt_tag( char *args
 )
{
    return get_uint( args, &( set.make_steganography_block.tag ) );
}

int callback_make_steganography_block_opt_length( char *args
 )
{
    return get_longuint( args, &( set.make_steganography_block.length ) );
}

int callback_make_steganography_block_opt_disable_folding( char *args
 )
{

    set.make_steganography_block.folding_en = 0;
    return 0;
}

int callback_make_steganography_block( char *args
 )
{

#if XMONOLITICEXECUTABLE == 0
    xrn_make_steg_block_dll = dlsym( set.xrnlib_dll, "xrn_make_steg_block" );
    if ( xrn_make_steg_block_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_make_steg_block_dll( set.make_steganography_block.filesource,
                                    set.make_steganography_block.fileenvelop,
                                    set.make_steganography_block.fileembedded,
                                    set.make_steganography_block.folding_en,
                                    set.make_steganography_block.tag,
                                    set.make_steganography_block.offset,
                                    set.make_steganography_block.length,
                                    set.common_settings.xrn_crypto_extra_settings );
}

int callback_get_capacity_opt_envelop_file( char *args
 )
{
    return getfile_r( args, &( set.get_capacity.fileenvelop ) );
}

int callback_get_capacity_opt_disable_folding( char *args
 )
{

    set.get_capacity.folding_en = 0;
    return 0;
}

int callback_get_capacity( char *args
 )
{
    uint64_t capacity;

#if XMONOLITICEXECUTABLE == 0
    xrn_estimate_steg_block_length_dll = dlsym( set.xrnlib_dll, "xrn_estimate_steg_block_length" );
    if ( xrn_estimate_steg_block_length_dll == NULL ) {
        return -1;
    }

#endif

    return xrn_estimate_steg_block_length_dll( set.get_capacity.fileenvelop,
                                               set.get_capacity.folding_en, &capacity );
}

int callback_convert_asymmetric_signature_to_binomial_key_opt_binomial_key( char
                                                                            *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_asymmetric_signature_to_binomial_key( char *args
 )
{
    set.conv_type.typein = c_signature_asy;
    set.conv_type.typeout = c_binomial_key;
    set.conv_type.in = set.arithmetic_settings.fpasy_signature;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_symmetric_signature_to_binomial_key_opt_binomial_key( char
                                                                           *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_symmetric_signature_to_binomial_key( char *args
 )
{
    set.conv_type.typein = c_signature_sym;
    set.conv_type.typeout = c_binomial_key;
    set.conv_type.in = set.arithmetic_settings.fpsym_signature;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_binomial_key_to_asymmetric_signature_opt_asymmetric_signature( char
                                                                                    *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_binomial_key_to_asymmetric_signature( char *args
 )
{
    set.conv_type.typein = c_binomial_key;
    set.conv_type.typeout = c_signature_asy;
    set.conv_type.in = set.arithmetic_settings.fpbinomial_key;

#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

int callback_convert_binomial_key_to_symmetric_signature_opt_symmetric_signature( char
                                                                                  *args
 )
{
    return getfile_w( args, &( set.conv_type.out ) );
}

int callback_convert_binomial_key_to_symmetric_signature( char *args
 )
{
    set.conv_type.typein = c_binomial_key;
    set.conv_type.typeout = c_signature_sym;
    set.conv_type.in = set.arithmetic_settings.fpbinomial_key;
#if XMONOLITICEXECUTABLE == 0
    xrn_convert_type_wrapper_dll = dlsym( set.xrnlib_dll, "xrn_convert_type_wrapper" );
    if ( xrn_convert_type_wrapper_dll == NULL ) {
        return -1;
    }

#endif
    return xrn_convert_type_wrapper_dll( set.conv_type.in, set.conv_type.out,
                                         set.conv_type.typein,
                                         set.conv_type.typeout,
                                         set.common_settings.xrn_crypto_extra_settings );
}

